57 int rest, this_read, bytes_read;
62 fprintf(stderr,
"Discard_Rest called to discard: %i\n",
len);
69 this_read = (rest >
sizeof(temp) ?
sizeof(temp) : rest);
71 bytes_read = read(con->
fd, temp, this_read);
73 if (bytes_read <= 0) {
84 rest = rest - bytes_read;
103 int len_sent, tot_sent, this_len;
107 struct iovec io_list[10];
114 len_sent = tot_sent = 0;
117 while ((pkt_ptr !=
NULL) & (i < 10)) {
119 this_len = pkt_ptr->
len;
120 this_data = pkt_ptr->
data;
121 if ((tot_sent + this_len) > len)
122 this_len = len - tot_sent;
130 tot_sent += this_len;
135 pkt_ptr = pkt_ptr->
next;
140 fprintf(stderr,
"Frags = %i, tot_sent = %i\n", i, tot_sent);
148 if ((len_sent = writev(con->
fd, io_list, i)) < 0) {
159 if (len_sent < tot_sent) {
172 fprintf(stderr,
"Len sent = %i ...\n", len_sent);
191 int read_len, pkt_len;
194 int more, this_time, offset, frag_len, this_len;
202 fprintf(stderr,
"Trying to read less than a packet:");
214 while (seen_keep_alive) {
216 if ((read_len = read(con->
fd, hdr,
sizeof(hdr))) < 0) {
218 fprintf(stderr,
"Reading the packet, we got:");
234 fprintf(stderr,
"Connection closed reading\n");
248 fprintf(stderr,
"RFCNB KEEP ALIVE received\n");
252 seen_keep_alive =
FALSE;
259 if (read_len <
sizeof(hdr)) {
263 memcpy(pkt->
data, hdr, read_len);
277 fprintf(stderr,
"Reading Pkt: Length = %i\n", pkt_len);
282 memcpy(pkt->
data, hdr,
sizeof(hdr));
297 if (pkt->
len == read_len) {
298 pkt_frag = pkt->
next;
305 frag_len = (pkt_frag ? pkt_frag->
len : 0);
307 if (more <= frag_len)
310 this_len = frag_len - offset;
314 if ((this_time = read(con->
fd, (pkt_frag->
data) + offset, this_len)) <= 0) {
316 if (errno == EINTR) {
332 fprintf(stderr,
"Frag_Len = %i, this_time = %i, this_len = %i, more = %i\n", frag_len,
333 this_time, this_len, more);
336 read_len = read_len + this_time;
343 pkt_frag = pkt_frag->
next;
344 this_len = pkt_frag->
len;
347 more = more - this_time;
352 fprintf(stderr,
"Pkt Len = %i, read_len = %i\n", pkt_len, read_len);
356 if (read_len < (pkt_len +
sizeof(hdr))) {
int RFCNB_Put_Pkt(struct RFCNB_Con *con, struct RFCNB_Pkt *pkt, int len)
int RFCNB_Get_Pkt(struct RFCNB_Con *con, struct RFCNB_Pkt *pkt, int len)
static int RFCNB_Discard_Rest(struct RFCNB_Con *con, int len)
#define RFCNB_Pkt_Hdr_Len
#define RFCNB_Pkt_Type(p)
#define RFCNB_SESSION_KEEP_ALIVE
void RFCNB_Print_Pkt(FILE *fd, char *dirn, struct RFCNB_Pkt *pkt, int len)