kevent behavior with TCP socket

Denis Berezhnoy denis.berezhnoy at gmail.com
Thu Aug 6 08:38:06 UTC 2009


Hi guys,


I have question regarding kevent behavior with TCP socket.  Hope you can
advise anything.


I am trying to connect the server in non block mode. When I call connect it
returns -1 and errno=EINPROGRESS. Then I use kqueue and kevent with
EVFILT_WRITE and timeout 100 msec to wait when server will be available to
accept connection.


kevent returns me 1 event without any timeout (filters = -2 (EVFILT_WRITE)
flags = 0 data = 43008)



So I consider this as server is ready to accept connection but when I check
socket error after kevent returns by

getsockopt with SOL_SOCKET and SO_ERROR params it returns me socket error
54  ECONNRESET /* Connection reset by peer */

and no connection can be established using this socket.


I am confused why kevent returns event that seems to indicate good condition
 but actual socket status indicates error. What I am doing wrong?


Sorry for this rough description of the problem my code is the part of large
system so I can not simply copy paste code.


I am using:


FreeBSD freebsd 7.1-RELEASE FreeBSD 7.1-RELEASE #0: Thu Jan  1 14:37:25 UTC
2009     root at logan.cse.buffalo.edu:/usr/obj/usr/src/sys/GENERIC  i386


Best regards

Denis


More information about the freebsd-net mailing list