- char *buf_ptr = save_buf + save_len;
- result = readsocket( sock, buf_ptr, SG_IO_MAX_MSG_SIZE - save_len );
- save_len += result;
+ if ( sock_style == SOCK_STREAM ) {
+ // cout << "sock_stream\n";
+ if ( msgsock == INVALID_SOCKET ) {
+ // cout << "msgsock == invalid\n";
+ msgsock = accept(sock, 0, 0);
+ closesocket(sock);
+ sock = msgsock;
+ } else {
+ // cout << "ready to read\n";
+ char *buf_ptr = save_buf + save_len;
+ result = readsocket( sock, buf_ptr, SG_IO_MAX_MSG_SIZE
+ - save_len );
+ // cout << "read result = " << result << endl;
+
+ if ( result > 0 ) {
+ first_read = true;
+ }
+
+ save_len += result;
+
+ // Try and detect that the remote end died. This
+ // could cause problems so if you see connections
+ // dropping for unexplained reasons, LOOK HERE!
+ if ( result == 0 && save_len == 0 && first_read == true ) {
+ SG_LOG( SG_IO, SG_ALERT,
+ "Connection closed by foreign host." );
+ closesocket(sock);
+ open( get_dir() );
+ }
+ }
+ } else {
+ char *buf_ptr = save_buf + save_len;
+ result = readsocket( sock, buf_ptr, SG_IO_MAX_MSG_SIZE - save_len );
+ save_len += result;
+ }
+