use rfbClientErr to log errors, check if calloc succeded (both hinted by Andre Leiradella)

pull/1/head
dscho 20 years ago
parent c641923d05
commit 7d3b1c9762

@ -24,7 +24,7 @@ archives and please don't beat me, if I forgot you, but just send me an
email!): Akira Hatakeyama, Karl J. Runge, Justin "Zippy" Dearing, email!): Akira Hatakeyama, Karl J. Runge, Justin "Zippy" Dearing,
Oliver Mihatsch, Greg Sternberg, Werner Hofer, Giampiero Giancipoli, Oliver Mihatsch, Greg Sternberg, Werner Hofer, Giampiero Giancipoli,
Glenn Mabutt, Paul Kreiner, Erik Kunze, Mike Frysinger, Martin Waitz, Glenn Mabutt, Paul Kreiner, Erik Kunze, Mike Frysinger, Martin Waitz,
Mark McLoughlin, Paul Fox, Juan Jose Costello. Mark McLoughlin, Paul Fox, Juan Jose Costello, Andre Leiadella.
Probably I forgot quite a few people sending a patch here and there, which Probably I forgot quite a few people sending a patch here and there, which
really made a difference. Without those, some obscure bugs still would really made a difference. Without those, some obscure bugs still would

@ -77,7 +77,7 @@ listenForIncomingConnections(rfbClient* client)
switch (fork()) { switch (fork()) {
case -1: case -1:
perror("fork"); rfbClientErr("fork");
return; return;
case 0: case 0:

@ -120,7 +120,7 @@ ReadFromRFBServer(rfbClient* client, char *out, unsigned int n)
*/ */
i = 0; i = 0;
} else { } else {
perror("read"); rfbClientErr("read");
return FALSE; return FALSE;
} }
} else { } else {
@ -149,7 +149,7 @@ ReadFromRFBServer(rfbClient* client, char *out, unsigned int n)
*/ */
i = 0; i = 0;
} else { } else {
perror("read"); rfbClientErr("read");
return FALSE; return FALSE;
} }
} else { } else {
@ -200,12 +200,12 @@ WriteToRFBServer(rfbClient* client, char *buf, int n)
FD_SET(client->sock,&fds); FD_SET(client->sock,&fds);
if (select(client->sock+1, NULL, &fds, NULL, NULL) <= 0) { if (select(client->sock+1, NULL, &fds, NULL, NULL) <= 0) {
perror("select"); rfbClientErr("select");
return FALSE; return FALSE;
} }
j = 0; j = 0;
} else { } else {
perror("write"); rfbClientErr("write");
return FALSE; return FALSE;
} }
} else { } else {
@ -236,19 +236,19 @@ ConnectClientToTcpAddr(unsigned int host, int port)
sock = socket(AF_INET, SOCK_STREAM, 0); sock = socket(AF_INET, SOCK_STREAM, 0);
if (sock < 0) { if (sock < 0) {
perror("ConnectToTcpAddr: socket"); rfbClientErr("ConnectToTcpAddr: socket");
return -1; return -1;
} }
if (connect(sock, (struct sockaddr *)&addr, sizeof(addr)) < 0) { if (connect(sock, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
perror("ConnectToTcpAddr: connect"); rfbClientErr("ConnectToTcpAddr: connect");
close(sock); close(sock);
return -1; return -1;
} }
if (setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, if (setsockopt(sock, IPPROTO_TCP, TCP_NODELAY,
(char *)&one, sizeof(one)) < 0) { (char *)&one, sizeof(one)) < 0) {
perror("ConnectToTcpAddr: setsockopt"); rfbClientErr("ConnectToTcpAddr: setsockopt");
close(sock); close(sock);
return -1; return -1;
} }
@ -274,7 +274,7 @@ FindFreeTcpPort(void)
sock = socket(AF_INET, SOCK_STREAM, 0); sock = socket(AF_INET, SOCK_STREAM, 0);
if (sock < 0) { if (sock < 0) {
perror(": FindFreeTcpPort: socket"); rfbClientErr(": FindFreeTcpPort: socket");
return 0; return 0;
} }
@ -308,25 +308,25 @@ ListenAtTcpPort(int port)
sock = socket(AF_INET, SOCK_STREAM, 0); sock = socket(AF_INET, SOCK_STREAM, 0);
if (sock < 0) { if (sock < 0) {
perror("ListenAtTcpPort: socket"); rfbClientErr("ListenAtTcpPort: socket");
return -1; return -1;
} }
if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR,
(const char *)&one, sizeof(one)) < 0) { (const char *)&one, sizeof(one)) < 0) {
perror("ListenAtTcpPort: setsockopt"); rfbClientErr("ListenAtTcpPort: setsockopt");
close(sock); close(sock);
return -1; return -1;
} }
if (bind(sock, (struct sockaddr *)&addr, sizeof(addr)) < 0) { if (bind(sock, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
perror("ListenAtTcpPort: bind"); rfbClientErr("ListenAtTcpPort: bind");
close(sock); close(sock);
return -1; return -1;
} }
if (listen(sock, 5) < 0) { if (listen(sock, 5) < 0) {
perror("ListenAtTcpPort: listen"); rfbClientErr("ListenAtTcpPort: listen");
close(sock); close(sock);
return -1; return -1;
} }
@ -349,13 +349,13 @@ AcceptTcpConnection(int listenSock)
sock = accept(listenSock, (struct sockaddr *) &addr, &addrlen); sock = accept(listenSock, (struct sockaddr *) &addr, &addrlen);
if (sock < 0) { if (sock < 0) {
perror("AcceptTcpConnection: accept"); rfbClientErr("AcceptTcpConnection: accept");
return -1; return -1;
} }
if (setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, if (setsockopt(sock, IPPROTO_TCP, TCP_NODELAY,
(char *)&one, sizeof(one)) < 0) { (char *)&one, sizeof(one)) < 0) {
perror("AcceptTcpConnection: setsockopt"); rfbClientErr("AcceptTcpConnection: setsockopt");
close(sock); close(sock);
return -1; return -1;
} }
@ -372,7 +372,7 @@ rfbBool
SetNonBlocking(int sock) SetNonBlocking(int sock)
{ {
if (fcntl(sock, F_SETFL, O_NONBLOCK) < 0) { if (fcntl(sock, F_SETFL, O_NONBLOCK) < 0) {
perror("AcceptTcpConnection: fcntl"); rfbClientErr("AcceptTcpConnection: fcntl");
return FALSE; return FALSE;
} }
return TRUE; return TRUE;

@ -91,6 +91,10 @@ static void initAppData(AppData* data) {
rfbClient* rfbGetClient(int bitsPerSample,int samplesPerPixel, rfbClient* rfbGetClient(int bitsPerSample,int samplesPerPixel,
int bytesPerPixel) { int bytesPerPixel) {
rfbClient* client=(rfbClient*)calloc(sizeof(rfbClient),1); rfbClient* client=(rfbClient*)calloc(sizeof(rfbClient),1);
if(!client) {
rfbClientErr("Couldn't allocate client structure!\n");
return 0;
}
initAppData(&client->appData); initAppData(&client->appData);
client->programName = 0; client->programName = 0;
client->endianTest = 1; client->endianTest = 1;

Loading…
Cancel
Save