Advertisement
Guest User

Untitled

a guest
May 20th, 2017
562
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.58 KB | None | 0 0
  1. [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() ?
  2. [20:11] * OMGAJD (~sof7@ficjo.users.quakenet.org) has joined #c++
  3. [20:14] * OMGAJD (~sof7@ficjo.users.quakenet.org) Quit (Read error: Connection reset by peer)
  4. [20:14] <Ensiferum> Damn3d: yes
  5. [20:15] * OMGAJD (~sof7@ficjo.users.quakenet.org) has joined #c++
  6. [20:16] * omgajdd (~sof7@ficjo.users.quakenet.org) Quit (Ping timeout)
  7. [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
  8. [20:17] <Ensiferum> Damn3d: you make the socket non-blocking, then you call connect and check the socket for readability
  9. [20:17] <Ensiferum> when its signaled to be read the connect has finished
  10. [20:17] <Ensiferum> and then you check the socket for error code
  11. [20:18] <Damn3d> Hm..
  12. [20:18] <Damn3d> So I'll be notified by select() by the same way as I am when sockets are readable?
  13. [20:19] <Ensiferum> yeah
  14. [20:20] <Damn3d> How do you check for socket error code?
  15. [20:20] * Krabbe is now known as krabbe
  16. [20:21] <Ensiferum> you call getsockopt
  17. [20:22] * pnk|[DC]remagT (~borim@root.on.every.dial-in.org) has joined #c++
  18. [20:23] <Ensiferum> you have to note that when you call connect on a non-blocking socket you'll get an error code
  19. [20:23] <Ensiferum> and then you'll have to check the specific error with errno/WSAGetError
  20. [20:23] <Ensiferum> and you get EINPROGRESS/WSAEWOULDBLOCK
  21. [20:24] * Beetny (~Beetny@ppp118-208-148-174.lns20.bne1.internode.on.net) has joined #c++
  22. [20:27] * pnk|[DC]remagT (~borim@root.on.every.dial-in.org) has left #c++
  23. [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)
  24. [20:27] <Ensiferum> just call getsockopt when the connecting socket is signaled
  25. [20:28] <Ensiferum> its only signaled when the connect is ready
  26. [20:28] <Ensiferum> FD_SET read;
  27. [20:28] <Ensiferum> FD_ZERO(&read);
  28. [20:29] <Ensiferum> FD_SET(connection_fd, &read); select(..., &read, NULL, NULL, NULL); if (FD_ISSET(connection_fd, &read)) getsockopt(...)
  29. [20:29] <Ensiferum> btw are you on *nix or win?
  30. [20:29] <Damn3d> Linux
  31. [20:30] <Ensiferum> aight
  32. [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() ?
  33. [20:30] <Damn3d> WAITING*
  34. [20:30] <Damn3d> without caps*.. :P
  35. [20:30] <Ensiferum> well that you need to take care of yourself
  36. [20:31] <Damn3d> Ok
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement