void DIS_tcp_setup(int fd) { struct tcp_chan *tcp; struct tcp_chan **tmpa; int rc; /* check for bad file descriptor */ if (fd < 0) return; rc = pbs_client_thread_lock_tcp(); assert(rc == 0); /* set DIS function pointers */ DIS_tcp_funcs(); if (fd >= tcparraymax) { int hold = tcparraymax; tcparraymax = fd+10; if (tcparray == NULL) { tcparray = (struct tcp_chan **) calloc(tcparraymax, sizeof(struct tcp_chan *)); assert(tcparray != NULL); } else { tmpa = (struct tcp_chan **)realloc(tcparray, tcparraymax * sizeof(struct tcp_chan *)); assert(tmpa != NULL); tcparray = tmpa; memset(&tcparray[hold], '\0', (tcparraymax-hold) * sizeof(struct tcp_chan *)); } } tcp = tcparray[fd]; if (tcp == NULL) { tcp = tcparray[fd] = (struct tcp_chan *)malloc(sizeof(struct tcp_chan)); assert(tcp != NULL); tcp->readbuf.tdis_thebuf = malloc(THE_BUF_SIZE); assert(tcp->readbuf.tdis_thebuf != NULL); tcp->readbuf.tdis_bufsize = THE_BUF_SIZE; tcp->writebuf.tdis_thebuf = malloc(THE_BUF_SIZE); assert(tcp->writebuf.tdis_thebuf != NULL); tcp->writebuf.tdis_bufsize = THE_BUF_SIZE; } /* initialize read and write buffers */ DIS_tcp_clear(&tcp->readbuf); DIS_tcp_clear(&tcp->writebuf); rc = pbs_client_thread_unlock_tcp(); assert(rc == 0); }
void DIS_tcp_reset( struct tcp_chan *chan, int i) { if (i == 0) DIS_tcp_clear(&chan->readbuf); else DIS_tcp_clear(&chan->writebuf); return; } /* END DIS_tcp_reset() */
struct tcp_chan * DIS_tcp_setup( int fd) { struct tcp_chan *chan = NULL; struct tcpdisbuf *tp = NULL; /* check for bad file descriptor */ if (fd < 0) { return(NULL); } if ((chan = (struct tcp_chan *)calloc(1, sizeof(struct tcp_chan))) == NULL) { log_err(ENOMEM, "DIS_tcp_setup", "calloc failure"); return(NULL); } /* Assign socket to struct */ chan->sock = fd; chan->reused = FALSE; /* Setting up the read buffer */ tp = &chan->readbuf; if ((tp->tdis_thebuf = (char *)calloc(1, THE_BUF_SIZE+1)) == NULL) { free(chan); log_err(errno,"DIS_tcp_setup","calloc failure"); return(NULL); } tp->tdis_bufsize = THE_BUF_SIZE; DIS_tcp_clear(tp); /* Setting up the write buffer */ tp = &chan->writebuf; if ((tp->tdis_thebuf = (char *)calloc(1, THE_BUF_SIZE+1)) == NULL) { free(chan->readbuf.tdis_thebuf); free(chan); log_err(errno,"DIS_tcp_setup","calloc failure"); return(NULL); } tp->tdis_bufsize = THE_BUF_SIZE; DIS_tcp_clear(tp); return(chan); } /* END DIS_tcp_setup() */
struct tcp_chan * DIS_tcp_setup( int fd) { struct tcp_chan *chan = NULL; struct tcpdisbuf *tp = NULL; /* check for bad file descriptor */ if (fd < 0) { return(NULL); } if ((chan = (struct tcp_chan *)calloc(1, sizeof(struct tcp_chan))) == NULL) { return(NULL); } /* Assign socket to struct */ tcpData *data = new tcpData(); fds.insert(std::pair<int,tcpData *>(fd,data)); chan->sock = fd; /* Setting up the read buffer */ tp = &chan->readbuf; if ((tp->tdis_thebuf = (char *)calloc(1, THE_BUF_SIZE+1)) == NULL) { delete data; free(chan); return(NULL); } tp->tdis_bufsize = THE_BUF_SIZE; DIS_tcp_clear(tp); /* Setting up the write buffer */ tp = &chan->writebuf; if ((tp->tdis_thebuf = (char *)calloc(1, THE_BUF_SIZE+1)) == NULL) { delete data; free(chan->readbuf.tdis_thebuf); free(chan); return(NULL); } tp->tdis_bufsize = THE_BUF_SIZE; DIS_tcp_clear(tp); return(chan); } /* END DIS_tcp_setup() */
/** * @brief * -wrapper function for DIS_tcp_clear. * * @param[in] fd - file descriptor * @param[in] i - read or write buf to clear * * @return Void * */ void DIS_tcp_reset(int fd, int i) { DIS_tcp_clear(i==0 ? tcp_get_readbuf(fd) : tcp_get_writebuf(fd)); }