extern void proto_session_hdr_unmarshall(Proto_Session *s, Proto_Msg_Hdr *h){ h->version = proto_session_hdr_unmarshall_version(s); h->type = proto_session_hdr_unmarshall_type(s); proto_session_hdr_unmarshall_sver(s, &h->sver); proto_session_hdr_unmarshall_pstate(s, &h->pstate); proto_session_hdr_unmarshall_gstate(s, &h->gstate); h->blen = proto_session_hdr_unmarshall_blen(s); }
extern int proto_session_rcv_msg(Proto_Session *s) { proto_session_reset_receive(s); // read reply ////////// ADD CODE ////////// if (PROTO_PRINT_DUMPS==1) fprintf(stderr, "Waiting to receive message\n"); int bytesRead = net_readn(s->fd, &s->rhdr, sizeof(Proto_Msg_Hdr)); // Read the reply header from received message if (PROTO_PRINT_DUMPS==1) fprintf(stderr, "Received %d bytes\n", bytesRead); // Make sure we read the # of bytes we expect if (bytesRead<(int)sizeof(Proto_Msg_Hdr)) { fprintf(stderr, "%s: ERROR failed to read len: %d!=%d" " ... closing connection\n", __func__, bytesRead, (int)sizeof(Proto_Msg_Hdr)); close(s->fd); return -1; } // Get the number of extra bytes in the blen field proto_session_hdr_unmarshall_blen(s); if (PROTO_PRINT_DUMPS==1) fprintf(stderr, "Number of bytes read: %d extraBytes=%d\n", bytesRead, s-> rhdr.blen); // Now read the read into the reply buffer bytesRead = net_readn(s->fd, &s->rbuf, s->rhdr.blen); if ( bytesRead != s->rhdr.blen) { fprintf(stderr, "%s: ERROR failed to read msg: %d!=%d" " .. closing connection\n" , __func__, bytesRead, s->rhdr.blen); close(s->fd); return -1; } ///////////////////// if (proto_debug()) { if(PROTO_PRINT_DUMPS==1) fprintf(stderr, "%p: proto_session_rcv_msg: RCVED:\n", pthread_self()); proto_session_dump(s); } if (PROTO_PRINT_DUMPS==1) fprintf(stderr, "Successfully received message\n" ); return 1; }