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) {
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;
return N_ERROR;
}
- dprintf(event->outfd,"[network] shutdown\n");
+ dprintf(net->outfd,"[network] shutdown\n");
return N_SUCCESS;
}
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;
}
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;
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;
}
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;
}
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;
}
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);
}
}
- dprintf(event->outfd,"[network] maximum connections reached\n");
+ dprintf(net->outfd,"[network] maximum connections reached\n");
return N_E_MAXC;
}
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) {
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) {
}
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;
}