From 927ab156f3ea4caac01e45e1d96e719fa3a53638 Mon Sep 17 00:00:00 2001 From: FreeArtMan Date: Sat, 25 Feb 2017 21:06:00 +0000 Subject: GLued up socket connectiona and messaging --- sock_conn.c | 40 ++++++++++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 14 deletions(-) (limited to 'sock_conn.c') diff --git a/sock_conn.c b/sock_conn.c index b15ce47..12a00a4 100644 --- a/sock_conn.c +++ b/sock_conn.c @@ -54,7 +54,6 @@ irc_buf* irc_buf_create() //cpy bytes from input to output int __irc_buf_drain_io(irc_buf *ib) { - int ret=-1; int cnt=0; int i; int j; @@ -62,35 +61,43 @@ int __irc_buf_drain_io(irc_buf *ib) //out buffer is allready full if (ib->out_size-1 == ib->max_out_size) { - printf("Out buffer is full\n"); + PRINT("Out buffer is full\n"); return -1; } //check if buffer is complete buffer - if ((ib->ready == 1) //its marked as complete - || + if (ib->ready == 1) //its marked as complete + { + PRINT("Buffear allready ready\n"); + return 0; + } + //in case if its not marked, -1 becouse its index in array - ((ib->out_size >= 2) + if ((ib->out_size >= 2) &&(ib->buf_out[ib->out_size-1]=='\n') - &&(ib->buf_out[ib->out_size-2]=='\r'))) + &&(ib->buf_out[ib->out_size-2]=='\r')) { - printf("Buffer is ready\n"); + PRINT("Buffer is ready\n"); return 0; } //lets from in buffer put as much as possible to out buffer i = ib->in_size-1; j = ib->out_size; - //PRINT("%d %d\n",i,j); + PRINT("in_size=%d out_size=%d\n",ib->in_size, ib->out_size); cnt = 0; while ((jmax_out_size)&&(i>=0)) //buffers ar full or empty { - if (ib->out_size >= 2) - if (((ib->buf_out[j-2]=='\r')&&(ib->buf_out[j-1]=='\n')))//bufferunderflow + //if (ib->out_size >= 2) + if (j >= 3) //be carefull with this line { - ib->ready = 1; - //PNL(); - break; + if (((ib->buf_out[j-3]=='\r')&&(ib->buf_out[j-2]=='\n')))//bufferunderflow + { + PRINT("READY\n"); + ib->ready = 1; + //PNL(); + break; + } } ib->buf_out[j] = ib->buf_in[i]; i--; @@ -101,14 +108,18 @@ int __irc_buf_drain_io(irc_buf *ib) PRINT("Copied %d bytes\n", cnt); ib->in_size = i+1; //i can end up as -1 ib->out_size = j; // + PRINT("in_size=%d out_size=%d\n",ib->in_size, ib->out_size); //if out buffer full and its doesnt have proper ending if (ib->out_size >= 2) if ((ib->buf_out[ib->out_size-1]=='\n')&&(ib->buf_out[ib->out_size-2]=='\r')) { + PRINT("READY\n"); ib->ready = 1; return cnt; } + PRINT("%d\n",cnt); + return cnt; } @@ -156,7 +167,7 @@ int irc_buf_puts(irc_buf *ib, char *in_buf, int sz) } //printf("%d %d\n",sz,cnt); - ret = cnt; + ret = fret; return ret; } @@ -262,6 +273,7 @@ int irc_connect( char *hostname, char *port ) if (0 != getaddrinfo(hostname, port, &serv, &res)) { PERM(); + perror("Couldnt get addr info"); return -1; } fd = socket(res->ai_family, res->ai_socktype, res->ai_protocol); -- cgit v1.2.3