From: hackbard Date: Fri, 29 Oct 2004 12:26:08 +0000 (+0000) Subject: bugfixes X-Git-Url: https://hackdaworld.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a88d4856f5c836896fc18f14d736c42c9d366352;p=my-code%2Fapi.git bugfixes --- diff --git a/event/event.c b/event/event.c index e3d60ab..398a1dd 100644 --- a/event/event.c +++ b/event/event.c @@ -22,6 +22,14 @@ int event_init(t_event *event,int outfd) { return E_SUCCESS; } +int event_set_timeout(t_event *event,int sec,int usec) { + + event->timeout.tv_sec=sec; + event->timeout.tv_usec=usec; + + return E_SUCCESS; +} + int event_math(int fd,t_event *event,char rw,char ar) { if(ar==ADD) { diff --git a/event/event.h b/event/event.h index b17983b..aadd65f 100644 --- a/event/event.h +++ b/event/event.h @@ -4,6 +4,7 @@ #define EVENT_H /* includes */ +#define _GNU_SOURCE #include #include #include @@ -38,6 +39,7 @@ typedef struct s_event { /* function prototypes */ int event_init(t_event *event,int outfd); +int event_set_timeout(t_event *event,int sec,int usec); int event_math(int fd,t_event *event,char rw,char ar); int event_start(t_event *event,void *ptr, int (*callback0)(t_event *event,void *ptr), diff --git a/network/network.c b/network/network.c index aefb7c2..7df2597 100644 --- a/network/network.c +++ b/network/network.c @@ -41,7 +41,7 @@ int network_listen(t_net *net) { perror("[network] setsockopt call"); return N_ERROR; } - dprintf(event->outfd,"[network] reused address\n"); + dprintf(net->outfd,"[network] reused address\n"); } if(listen(net->l_fd,MAX_LISTEN_QUEUE)==-1) { @@ -49,7 +49,7 @@ int network_listen(t_net *net) { return N_ERROR; } - dprintf(event->outfd,"[network] listen on %s port %d\n", + dprintf(net->outfd,"[network] listen on %s port %d\n", inet_ntoa(addr.sin_addr),net->l_port); return N_SUCCESS; @@ -68,7 +68,7 @@ int network_shutdown(t_net *net) { return N_ERROR; } - dprintf(event->outfd,"[network] shutdown\n"); + dprintf(net->outfd,"[network] shutdown\n"); return N_SUCCESS; } @@ -94,7 +94,7 @@ int network_manage_connection(t_net *net) { perror("[network] close call"); return N_E_CLOSE; } - dprintf(event->outfd,"[network] connection %d closed\n",i); + dprintf(net->outfd,"[network] connection %d closed\n",i); net->connection[i].status=0; } @@ -125,8 +125,8 @@ int network_manage_connection(t_net *net) { return N_E_CONNECT; } - dprintf(event->outfd,"[network] established connection to "); - dprintf(event->outfd,"%s port %d on channel %d\n", + dprintf(net->outfd,"[network] established connection to "); + dprintf(net->outfd,"%s port %d on channel %d\n", net->connection[i].ip,net->connection[i].port,i); net->connection[i].status|=C_ESTABL; @@ -144,12 +144,12 @@ int network_manage_connection(t_net *net) { int network_connect(t_net *net,int channel) { if(net->connection[channel].status&C_IN_USE) { - dprintf(event->outfd,"[network] connect failed, channel %02d in use\n", + dprintf(net->outfd,"[network] connect failed, channel %02d in use\n", channel); return N_E_IN_USE; } if(!(net->connection[channel].status&C_INFO_A)) { - dprintf(event->outfd, + dprintf(net->outfd, "[network] connect failed, missing config for chan %02d\n",channel); return N_E_NO_INFO; } @@ -162,7 +162,7 @@ int network_connect(t_net *net,int channel) { int network_close(t_net *net,int channel) { if(!(net->connection[channel].status&C_ESTABL)) { - dprintf(event->outfd,"[network] close failed, channel %02d not active\n", + dprintf(net->outfd,"[network] close failed, channel %02d not active\n", channel); return N_E_NC; } @@ -184,7 +184,7 @@ int network_close_all(t_net *net) { int network_set_connection_info(t_net *net,int channel,char *ip,int port) { if(net->connection[channel].status&C_IN_USE) { - dprintf(event->outfd, + dprintf(net->outfd, "[network] set connection failed, channel %02d in use\n",channel); return N_E_IN_USE; } @@ -235,7 +235,7 @@ int network_manage_incoming(t_net *net) { strncpy(net->connection[channel].ip,inet_ntoa(addr.sin_addr),IP_DIGITS); net->connection[channel].port=ntohs(addr.sin_port); net->connection[channel].status=C_IN_USE|C_INFO_A|C_SOCKET|C_ESTABL; - dprintf(event->outfd, + dprintf(net->outfd, "[network] established connection from %s:%d, channel %d\n", net->connection[channel].ip,net->connection[channel].port, channel); @@ -243,7 +243,7 @@ int network_manage_incoming(t_net *net) { } } - dprintf(event->outfd,"[network] maximum connections reached\n"); + dprintf(net->outfd,"[network] maximum connections reached\n"); return N_E_MAXC; } @@ -267,14 +267,20 @@ int network_send(int fd,unsigned char *data,int datasize) { int network_receive(int fd,unsigned char *data,int datasize) { - int count; + int count,left; - if((count=read(fd,data,datasize))==-1) { - perror("[network] read call"); - return N_ERROR; + count=0; + left=datasize; + + while(left) { + if((count=read(fd,data,datasize))==-1) { + perror("[network] read call"); + return N_ERROR; + } + left-=count; } - return count; + return datasize; } int network_udp_listen_init(t_net *net) { @@ -299,10 +305,10 @@ int network_udp_listen_init(t_net *net) { perror("[network] setsockopt call (udp)"); return N_ERROR; } - dprintf(event->outfd,"[network] reused address (udp)\n"); + dprintf(net->outfd,"[network] reused address (udp)\n"); } - dprintf(event->outfd,"[network] listening on port %d (udp)\n", + dprintf(net->outfd,"[network] listening on port %d (udp)\n", net->l_udp_port); if((net->s_udp_fd=socket(AF_INET,SOCK_DGRAM,0))==-1) { @@ -325,7 +331,7 @@ int network_udp_receive(t_net *net,int channel, unsigned char *data,int count) { } if(strncmp(net->connection[channel].ip,inet_ntoa(addr.sin_addr),IP_DIGITS)) { - dprintf(event->outfd,"[network] packet from unknown: %s\n", + dprintf(net->outfd,"[network] packet from unknown: %s\n", inet_ntoa(addr.sin_addr)); return N_UDP_WRONG_SENDER; } diff --git a/network/network.h b/network/network.h index 281a43f..bfb4ab4 100644 --- a/network/network.h +++ b/network/network.h @@ -4,6 +4,7 @@ #define NETWORK_H /* includes */ +#define _GNU_SOURCE #include #include #include