Update of /cvsroot/agd/client
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24697
Modified Files:
net.c
Log Message:
Errors are now displayed with gui_printf; net_send
Index: net.c
===================================================================
RCS file: /cvsroot/agd/client/net.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- net.c 3 Aug 2004 14:50:13 -0000 1.1
+++ net.c 5 Aug 2004 13:25:28 -0000 1.2
@@ -10,50 +10,50 @@
int fd;
fd_set readfd;
-void net_connect() {
+int net_connect() {
struct sockaddr_in sin;
int ret;
#ifdef WIN32
WSADATA wsaData;
if(WSAStartup(MAKEWORD(1, 1), &wsaData)) {
- fprintf(stderr, "Can't initialize Winsock!\n");
- exit(1);
+ gui_printf(screen, "Can't initialize Winsock");
+ return 0;
}
#endif
sin.sin_family = AF_INET;
sin.sin_port = htons(conf.port);
- printf("port: %d\n", conf.port);
if(conf.host[0] > '0' && conf.host[0] < '9') {
/* This is an IP address. */
if(!inet_aton(conf.host, &sin.sin_addr)) {
- printf("Invalid IP address '%s'.\n", conf.host);
- return;
+ gui_printf(screen, "Invalid IP address '%s'.\n", conf.host);
+ return 0;
}
} else {
/* This is a hostname. */
struct hostent *he;
he = gethostbyname(conf.host);
if(!he) {
- printf("Cannot look up %s.\n", conf.host);
- return;
+ gui_printf(screen, "Cannot look up %s.\n", conf.host);
+ return 0;
}
sin.sin_addr = *(struct in_addr *)he->h_addr;
}
fd = socket(PF_INET, SOCK_STREAM, 0);
if(fd < 0) {
- perror("Can't open socket");
- exit(1);
+ gui_printf(screen, "Can't open socket: %s", strerror(errno));
+ return 0;
}
ret = connect(fd, (struct sockaddr *) &sin, sizeof sin);
if(ret < 0) {
- perror("Can't connect");
- exit(1);
+ gui_printf(screen, "Can't connect: %s", strerror(errno));
+ return 0;
}
+ return 1;
}
void net_events() {
@@ -66,26 +66,34 @@
ret = select(fd + 1, &readfd, 0, 0, &timeout);
if(ret <= 0) {
- if(ret < 0 )
+ if(ret < 0)
perror("select");
return;
}
if(FD_ISSET(fd, &readfd)) {
+ memset(buf, 0, 4096);
ret = recv(fd, buf, 4096, 0);
switch(ret) {
case -1:
- printf("Error reading from server\n");
+ gui_printf(screen, "Error reading from server\n");
/* fallthrough */
case 0:
- printf("Disconnected from server.\n");
- break;
+ gui_printf(screen, "Disconnected");
+ readkey();
+ exit(1);
default:
/* p = buf;
while(strlen(p)) {*/
- gui_label(screen, 0, buf, 0, cursor_y, SCREEN_W, SCREEN_H);
- cursor_y += fonts[0].b->h;
+ gui_printf(screen, buf);
+/* gui_label(screen, 0, buf, 0, cursor_y, SCREEN_W, SCREEN_H);
+ cursor_y += fonts[0].b->h;*/
break;
}
}
}
+
+void net_send(char *buf, int len)
+{
+ send(fd, buf, len, 0);
+}
|