SocketHandlers own the poller and add themself into it only when the socket is created

We want to call socket() with the parameters provided by getaddrinfo, so we
can’t addd the fd into the poller immediately. We need to wait the
connection attempt, and then the SocketHandler can call add_socket_handler
itself, if the connection succeeds, or is in progress.
This commit is contained in:
Florent Le Coz
2014-05-27 01:01:44 +02:00
parent 6b0ffb5fc2
commit 5507adbe94
11 changed files with 29 additions and 39 deletions
+2 -2
View File
@@ -42,7 +42,7 @@ public:
* Add a SocketHandler to be monitored by this Poller. All receive events
* are always automatically watched.
*/
void add_socket_handler(std::shared_ptr<SocketHandler> socket_handler);
void add_socket_handler(SocketHandler* socket_handler);
/**
* Remove (and stop managing) a SocketHandler, designed by the given socket_t.
*/
@@ -77,7 +77,7 @@ private:
* because that's what is returned by select/poll/etc when an event
* occures.
*/
std::unordered_map<socket_t, std::shared_ptr<SocketHandler>> socket_handlers;
std::unordered_map<socket_t, SocketHandler*> socket_handlers;
#if POLLER == POLL
struct pollfd fds[MAX_POLL_FD_NUMBER];