src/Network/Socket.hh
changeset 400 d64bf28c4340
parent 399 c7295b72731a
child 418 194bc810a570
equal deleted inserted replaced
399:c7295b72731a 400:d64bf28c4340
   145          * Get the socket fd... promise not to break it
   145          * Get the socket fd... promise not to break it
   146          */
   146          */
   147         int get_socket (void) const { return fd; }
   147         int get_socket (void) const { return fd; }
   148 
   148 
   149         /**
   149         /**
   150          * Bind to a specific local address
   150          * Bind to a local endpoint. This can be specified in hostname form, and a suitable socket will be chosen.
   151          */ 
   151          */ 
   152         void bind (const NetworkEndpoint &addr);
   152         void bind (const NetworkEndpoint &addr);
   153 
   153 
   154         /**
   154         /**
   155          * Put socket into listen mode
   155          * Put socket into listen mode for accept()
   156          */
   156          */
   157         void listen (int backlog);
   157         void listen (int backlog);
   158 
   158 
   159         /**
   159         /**
   160          * Get local address
   160          * Get local address
       
   161          *
       
   162          * Note that this may block on a reverse DNS lookup.
   161          */
   163          */
   162         NetworkAddress get_local_address (void); 
   164         NetworkAddress get_local_address (void); 
   163 
   165 
   164         /**
   166         /**
   165          * Get remote address
   167          * Get remote address
       
   168          *
       
   169          * Note that this may block on a reverse DNS lookup.
   166          */
   170          */
   167         NetworkAddress get_remote_address (void); 
   171         NetworkAddress get_remote_address (void); 
   168 
   172 
   169         /**
   173         /**
   170          * Make send/recv/connect non-blocking
   174          * Make send/recv non-blocking. The current connect() implementation does not support use of non-blocking
       
   175          * connects.
   171          */
   176          */
   172         void set_nonblocking (bool nonblocking);
   177         void set_nonblocking (bool nonblocking);
   173 
   178 
   174         /**
   179         /**
   175          * Accept a new connection, optionally giving the connection's source address
   180          * Accept an incoming connection on a listen() socket as a new socket, optionally storing the connection's
       
   181          * source address.
       
   182          *
       
   183          * Note that this may block on a reverse DNS lookup if \a src is given.
   176          */
   184          */
   177         NetworkSocket* accept (NetworkAddress *src);
   185         NetworkSocket* accept (NetworkAddress *src);
   178 
   186 
   179         /**
   187         /**
   180          * Establish a new connection
   188          * Connect this socket to a remote endpoint, going through the resolved addresses until we find one that works.
       
   189          *
       
   190          * This is currently implemented in an entirely blocking fashion, DNS lookups and connect() included.
   181          */
   191          */
   182         void connect (const NetworkEndpoint &addr);
   192         void connect (const NetworkEndpoint &addr);
   183 
   193 
   184         /**
   194         /**
   185          * Send, optionally using the specific destination
   195          * Send, optionally using the specific destination
   223          * Register to NetworkReactor unless already registered
   233          * Register to NetworkReactor unless already registered
   224          */
   234          */
   225         void register_poll (void);
   235         void register_poll (void);
   226 
   236 
   227         /**
   237         /**
   228          * Trigger sig_read() once socket is ready for recv?
   238          * Trigger sig_read() once socket is ready for recv()
   229          */
   239          */
   230         void set_poll_read (bool want_read) { this->want_read = want_read; if (!registered) register_poll(); }
   240         void set_poll_read (bool want_read) { this->want_read = want_read; if (!registered) register_poll(); }
   231 
   241 
   232         /**
   242         /**
   233          * Trigger sig_write() once socket is ready for send?
   243          * Trigger sig_write() once socket is ready for send()
   234          */
   244          */
   235         void set_poll_write (bool want_write) { this->want_write = want_write; if (!registered) register_poll(); }
   245         void set_poll_write (bool want_write) { this->want_write = want_write; if (!registered) register_poll(); }
   236 
   246 
   237         /**
   247         /**
   238          * What events this socket is interested in.
   248          * What events this socket is interested in (called by NetworkReactor)
   239          */
   249          */
   240         NetworkPollMask get_poll (void) { 
   250         NetworkPollMask get_poll (void) { 
   241             return (want_read ? POLL_READ : 0) | (want_write ? POLL_WRITE : 0); 
   251             return (want_read ? POLL_READ : 0) | (want_write ? POLL_WRITE : 0); 
   242         }
   252         }
   243 
   253 
   244         /**
   254         /**
   245          * Notify of events
   255          * Notify of events (called by NetworkReactor)
   246          */
   256          */
   247         void notify (NetworkPollMask mask) { 
   257         void notify (NetworkPollMask mask) { 
   248             if (mask & POLL_READ) _sig_read();
   258             if (mask & POLL_READ) _sig_read();
   249             if (mask & POLL_WRITE) _sig_write();
   259             if (mask & POLL_WRITE) _sig_write();
   250         }
   260         }