Logo Search packages:      
Sourcecode: libsocket version File versions  Download package

void Network::Socket::_set_timeout ( bool  enable,
int  socket,
int  timeout 
) [protected, inherited]

set a timeout on a socket

Parameters:
timeout is in second
Exceptions:
Timeout when there is a timeout
SelectError when select libc function return a negative value

Definition at line 268 of file socket.cc.

Referenced by Network::NetSocket::_read_line(), Network::NetSocket::read(), Network::LocalSocket::read(), Network::NetSocket::readn(), and Network::LocalSocket::readn().

  {
    fd_set        fdset;
    struct timeval      timetowait;
    int           res;

    if (enable)
      timetowait.tv_sec = timeout;
    else
      timetowait.tv_sec = 65535;
    timetowait.tv_usec = 0;
    FD_ZERO(&fdset);
    FD_SET(socket, &fdset);
    if (enable)
      res = select(socket + 1, &fdset, NULL, NULL, &timetowait);
    else
      res = select(socket + 1, &fdset, NULL, NULL, NULL);
    if (res < 0)
      throw SelectError("Select error", HERE);
    if (res == 0)
      throw Timeout("Timeout on socket", HERE);
  }


Generated by  Doxygen 1.6.0   Back to index