Hopefully more portable (notably for Windows)

This commit is contained in:
Pierre Pronchery 2012-11-17 18:24:05 +01:00
parent ed4460476c
commit f4676ba5ff
2 changed files with 28 additions and 10 deletions

View File

@ -27,12 +27,21 @@
#include <string.h> #include <string.h>
#include <limits.h> #include <limits.h>
#include <errno.h> #include <errno.h>
#include <netinet/in.h> #ifdef __WIN32__
#include <arpa/inet.h> # include <Winsock2.h>
#include <netdb.h> #else
# include <netinet/in.h>
# include <arpa/inet.h>
# include <netdb.h>
#endif
#include <System.h> #include <System.h>
#include "App/apptransport.h" #include "App/apptransport.h"
/* portability */
#ifdef __WIN32__
# define close(fd) closesocket(fd)
#endif
/* TCP */ /* TCP */
/* private */ /* private */
@ -539,8 +548,8 @@ static int _tcp_socket_callback_read(int fd, TCPSocket * tcpsocket)
if((p = realloc(tcpsocket->bufin, tcpsocket->bufin_cnt + inc)) == NULL) if((p = realloc(tcpsocket->bufin, tcpsocket->bufin_cnt + inc)) == NULL)
return -1; return -1;
tcpsocket->bufin = p; tcpsocket->bufin = p;
if((ssize = read(tcpsocket->fd, &tcpsocket->bufin[tcpsocket->bufin_cnt], if((ssize = recv(tcpsocket->fd, &tcpsocket->bufin[tcpsocket->bufin_cnt],
inc)) < 0) inc, 0)) < 0)
{ {
error_set_code(1, "%s", strerror(errno)); error_set_code(1, "%s", strerror(errno));
close(tcpsocket->fd); close(tcpsocket->fd);
@ -579,8 +588,8 @@ static int _tcp_socket_callback_write(int fd, TCPSocket * tcpsocket)
/* check parameters */ /* check parameters */
if(tcpsocket->fd != fd) if(tcpsocket->fd != fd)
return -1; return -1;
if((ssize = write(tcpsocket->fd, tcpsocket->bufout, if((ssize = send(tcpsocket->fd, tcpsocket->bufout,
tcpsocket->bufout_cnt)) < 0) tcpsocket->bufout_cnt, 0)) < 0)
{ {
/* XXX report error (and reconnect) */ /* XXX report error (and reconnect) */
error_set_code(1, "%s", strerror(errno)); error_set_code(1, "%s", strerror(errno));

View File

@ -25,12 +25,21 @@
#include <string.h> #include <string.h>
#include <limits.h> #include <limits.h>
#include <errno.h> #include <errno.h>
#include <netinet/in.h> #ifdef __WIN32__
#include <arpa/inet.h> # include <Winsock2.h>
#include <netdb.h> #else
# include <netinet/in.h>
# include <arpa/inet.h>
# include <netdb.h>
#endif
#include <System.h> #include <System.h>
#include "App/apptransport.h" #include "App/apptransport.h"
/* portability */
#ifdef __WIN32__
# define close(fd) closesocket(fd)
#endif
/* UDP */ /* UDP */
/* private */ /* private */