Wrote server under Linux. I start, connect to it through the browser. When I close the tab, the server drops to the next line.

if (send(s, &message[0], message.length(), 0) == SOCKET_ERROR) { throw std::string("Unable to send() string: ") + toString(errno); } 

The exception is not caught.

  • 2
    message is std :: string? When closing a socket, send may return EPIPE , or it may send a signal. - KoVadim
  • yes, std :: string. - feelGood
  • Added a check that returns send int res = send (s, & message [0], message.length (), 0); std :: cout << "res" << res << std :: endl; So nothing on the screen and displays. The application crashes when sending a message. How can I fix this? - feelGood
  • one
    As @KoVadim already said, most likely the signal is SIGPIPE. Those. no reader (the client has already called close () on its side). You can try to send() MSG_NOSIGNAL flag to send() in Linux. Either block this signal (sigprocmask () / sighold ()) or intercept (sigaction () / signal ()) or you can ignore (sigaction () / signal ()). Do you have SOCKET_ERROR -1? - avp
  • one
    @feelGood, I wrote you a bunch of tips there, and I usually just do the signal (SIGPIPE, SIG_IGN); somewhere at the beginning of the program. - avp

0