i have written complex library managing network communication based on iocp mechanism. problem when server closes connection calling api method closesocket() information transmitted client delayed seconds or minutes. code detecting connection closure looks (simplified):
ok = getqueuedcompletionstatus(completion_port, &io_size, (pulong_ptr)&context, &overlapped, 40); if (!ok) { // went broken dword err = getlasterror(); if (err == error_connection_refused) { // connection failed } else if (err == error_sem_timeout) { // connection timeout } else if (err == error_netname_deleted) { // connection closure - point of interest } else if (err != wait_timeout) { // unknown error } } else { // process incomming or outgoing data } why happening? need know connection closure able connect backup server (not heavily loaded - disconnect happening because of this).
how closing connection?
if you're calling closesocket() initiating shutdown sequence attempt ensure data pending reach destination. can take time, if network connection has been overloaded , datagrams have been lost , tcp retransmission occurring.
if want close connection straight away, , lose pending data, set linger 0 , close socket. issue rst on connection , you'll quicker.
Comments
Post a Comment