/** * @brief read a batch reply from the given socket * * @param[in] sock - The socket fd to read from * @param[out] rc - Return DIS error code * * @return Batch reply structure * @retval !NULL - Success * @retval NULL - Failure * */ struct batch_reply * PBSD_rdrpy_sock(int sock, int *rc) { struct batch_reply *reply; time_t old_timeout; *rc = DIS_SUCCESS; /* clear any prior error message */ if ((reply = (struct batch_reply *)malloc(sizeof(struct batch_reply))) == 0) { pbs_errno = PBSE_SYSTEM; return ((struct batch_reply *)0); } (void)memset(reply, 0, sizeof(struct batch_reply)); DIS_tcp_setup(sock); old_timeout = pbs_tcp_timeout; if (pbs_tcp_timeout < PBS_DIS_TCP_TIMEOUT_LONG) pbs_tcp_timeout = PBS_DIS_TCP_TIMEOUT_LONG; if ((*rc = decode_DIS_replyCmd(sock, reply)) != 0) { (void)free(reply); pbs_errno = PBSE_PROTOCOL; return (struct batch_reply *)NULL; } DIS_tcp_reset(sock, 0); /* reset DIS read buffer */ pbs_tcp_timeout = old_timeout; pbs_errno = reply->brp_code; return reply; }
int parse_response_svr( int sock, char **err_msg) { /* * PBS_BATCH_PROT_TYPE * PBS_BATCH_PROT_VER * reply->brp_code * reply->brp_auxcode * reply->brp_choice * if reply->brp_choice == BATCH_REPLY_CHOICE_Text also read: * preq->rq_reply.brp_un.brp_txt.brp_str * using * preq->rq_reply.brp_un.brp_txt.brp_txtlen */ int rc = PBSE_NONE; struct batch_reply *reply = NULL; char *tmp_val = NULL; struct tcp_chan *chan = NULL; if ((chan = DIS_tcp_setup(sock)) == NULL) { } else if ((reply = (struct batch_reply *)calloc(1, sizeof(struct batch_reply))) == NULL) { } else if ((rc = decode_DIS_replyCmd(chan, reply))) { free(reply); if (chan->IsTimeout == TRUE) { rc = PBSE_TIMEOUT; } else { rc = PBSE_PROTOCOL; } if ((tmp_val = pbs_strerror(rc)) == NULL) { char err_buf[80]; snprintf(err_buf, 79, "Error creating error message for code %d", rc); *err_msg = strdup(err_buf); } else *err_msg = strdup(tmp_val); } else { rc = reply->brp_code; if (reply->brp_code != PBSE_NONE) { *err_msg = strdup(reply->brp_un.brp_txt.brp_str); } free(reply); } DIS_tcp_cleanup(chan); return rc; }
struct batch_reply *PBSD_rdrpy( int *local_errno, /* O */ int c) /* I */ { int rc; struct batch_reply *reply; int sock; const char *the_msg = NULL; struct tcp_chan *chan = NULL; sock = connection[c].ch_socket; /* clear any prior error message */ if (connection[c].ch_errtxt != NULL) { free(connection[c].ch_errtxt); connection[c].ch_errtxt = NULL; } if ((reply = (struct batch_reply *)calloc(1, sizeof(struct batch_reply))) == NULL) { connection[c].ch_errno = PBSE_SYSTEM; *local_errno = PBSE_SYSTEM; return(NULL); } if ((chan = DIS_tcp_setup(sock)) == NULL) { } else if ((rc = decode_DIS_replyCmd(chan, reply))) { free(reply); if (chan->IsTimeout == TRUE) { *local_errno = PBSE_TIMEOUT; } else { *local_errno = PBSE_PROTOCOL; } connection[c].ch_errno = *local_errno; if ((rc >= 0) && (rc <= DIS_INVALID)) { if ((the_msg = dis_emsg[rc]) != NULL) { connection[c].ch_errtxt = strdup(the_msg); } } DIS_tcp_cleanup(chan); return(NULL); } DIS_tcp_cleanup(chan); connection[c].ch_errno = reply->brp_code; *local_errno = reply->brp_code; if (reply->brp_choice == BATCH_REPLY_CHOICE_Text) { if ((the_msg = reply->brp_un.brp_txt.brp_str) != NULL) { connection[c].ch_errtxt = strdup(the_msg); } } return(reply); } /* END PBSD_rdrpy() */