Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [20:10] <Damn3d> I'm using a select() loop to check for readability of sockets and listeners. Is this possible to use select() to handle non-blocking connect() ?
- [20:11] * OMGAJD (~sof7@ficjo.users.quakenet.org) has joined #c++
- [20:14] * OMGAJD (~sof7@ficjo.users.quakenet.org) Quit (Read error: Connection reset by peer)
- [20:14] <Ensiferum> Damn3d: yes
- [20:15] * OMGAJD (~sof7@ficjo.users.quakenet.org) has joined #c++
- [20:16] * omgajdd (~sof7@ficjo.users.quakenet.org) Quit (Ping timeout)
- [20:16] <Damn3d> Ensiferum Do I have to use additional set for them? Cause currently I'm storing both listeners + sockets at the same set
- [20:17] <Ensiferum> Damn3d: you make the socket non-blocking, then you call connect and check the socket for readability
- [20:17] <Ensiferum> when its signaled to be read the connect has finished
- [20:17] <Ensiferum> and then you check the socket for error code
- [20:18] <Damn3d> Hm..
- [20:18] <Damn3d> So I'll be notified by select() by the same way as I am when sockets are readable?
- [20:19] <Ensiferum> yeah
- [20:20] <Damn3d> How do you check for socket error code?
- [20:20] * Krabbe is now known as krabbe
- [20:21] <Ensiferum> you call getsockopt
- [20:22] * pnk|[DC]remagT (~borim@root.on.every.dial-in.org) has joined #c++
- [20:23] <Ensiferum> you have to note that when you call connect on a non-blocking socket you'll get an error code
- [20:23] <Ensiferum> and then you'll have to check the specific error with errno/WSAGetError
- [20:23] <Ensiferum> and you get EINPROGRESS/WSAEWOULDBLOCK
- [20:24] * Beetny (~Beetny@ppp118-208-148-174.lns20.bne1.internode.on.net) has joined #c++
- [20:27] * pnk|[DC]remagT (~borim@root.on.every.dial-in.org) has left #c++
- [20:27] <Damn3d> Okay, So I'd need to create a variable in order to check if the socket is already connected, right ? (Calling getsockopt() on every read availability would be stupid)
- [20:27] <Ensiferum> just call getsockopt when the connecting socket is signaled
- [20:28] <Ensiferum> its only signaled when the connect is ready
- [20:28] <Ensiferum> FD_SET read;
- [20:28] <Ensiferum> FD_ZERO(&read);
- [20:29] <Ensiferum> FD_SET(connection_fd, &read); select(..., &read, NULL, NULL, NULL); if (FD_ISSET(connection_fd, &read)) getsockopt(...)
- [20:29] <Ensiferum> btw are you on *nix or win?
- [20:29] <Damn3d> Linux
- [20:30] <Ensiferum> aight
- [20:30] <Damn3d> You said that I'd be notified by the same way as on readability. So how can I check if I'm aiting for connect() or for recv() ?
- [20:30] <Damn3d> WAITING*
- [20:30] <Damn3d> without caps*.. :P
- [20:30] <Ensiferum> well that you need to take care of yourself
- [20:31] <Damn3d> Ok
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement