comparison nnchat.c @ 53:7b98da167a0b

Improved error handling.
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 07 Nov 2008 22:17:44 +0200
parents cf7789d88350
children f6666e7c1a48
comparison
equal deleted inserted replaced
52:8d9c065241b7 53:7b98da167a0b
370 wattrset(editWin, A_NORMAL); 370 wattrset(editWin, A_NORMAL);
371 } 371 }
372 wrefresh(editWin); 372 wrefresh(editWin);
373 } 373 }
374 374
375 int openConnection(struct in_addr *addr, int port) 375 int openConnection(struct in_addr *addr, const int port)
376 { 376 {
377 struct sockaddr_in tmpAddr; 377 struct sockaddr_in tmpAddr;
378 int sock = -1; 378 int sock = -1;
379 379
380 tmpAddr.sin_family = AF_INET; 380 tmpAddr.sin_family = AF_INET;
398 398
399 return sock; 399 return sock;
400 } 400 }
401 401
402 402
403 void closeConnection(int sock) 403 void closeConnection(const int sock)
404 { 404 {
405 if (sock >= 0) { 405 if (sock >= 0) {
406 close(sock); 406 close(sock);
407 } 407 }
408 } 408 }
409 409
410 410
411 BOOL sendToSocket(int sock, char *buf, const size_t bufLen) 411 BOOL sendToSocket(const int sock, char *buf, const size_t bufLen)
412 { 412 {
413 size_t bufLeft = bufLen; 413 size_t bufLeft = bufLen;
414 char *bufPtr = buf; 414 char *bufPtr = buf;
415 415
416 while (bufLeft > 0) { 416 while (bufLeft > 0) {
1303 /* Check for incoming data from the server */ 1303 /* Check for incoming data from the server */
1304 tv.tv_sec = 0; 1304 tv.tv_sec = 0;
1305 tv.tv_usec = SET_DELAY_USEC; 1305 tv.tv_usec = SET_DELAY_USEC;
1306 tmpfds = sockfds; 1306 tmpfds = sockfds;
1307 if ((result = select(tmpSocket+1, &tmpfds, NULL, NULL, &tv)) == -1) { 1307 if ((result = select(tmpSocket+1, &tmpfds, NULL, NULL, &tv)) == -1) {
1308 printMsg("Error occured in select(sockfds): %s\n", 1308 if (errno != EINTR && errno != ERESTART) {
1309 strerror(errno)); 1309 printMsg("Error occured in select(sockfds): %d, %s\n", errno, strerror(errno));
1310 isError = TRUE; 1310 isError = TRUE;
1311 }
1311 } else if (FD_ISSET(tmpSocket, &tmpfds)) { 1312 } else if (FD_ISSET(tmpSocket, &tmpfds)) {
1312 ssize_t gotBuf; 1313 ssize_t gotBuf;
1313 char tmpBuf[8192]; 1314 char tmpBuf[8192];
1314 char *bufPtr = tmpBuf; 1315 char *bufPtr = tmpBuf;
1315 gotBuf = recv(tmpSocket, tmpBuf, sizeof(tmpBuf), 0); 1316 gotBuf = recv(tmpSocket, tmpBuf, sizeof(tmpBuf), 0);