summaryrefslogtreecommitdiff
path: root/src/server_get.c
diff options
context:
space:
mode:
authorJakub Sławiński2005-07-03 23:15:19 +0200
committerJoshua Judson Rosen2014-07-17 21:14:59 +0200
commitf2e4a5f9b0919dc16ea83a8826e8d52b02178b38 (patch)
treed226d27a9b81d67fc4493b7b1856c0b040267d77 /src/server_get.c
parentv0.7 (diff)
downloadapf-f2e4a5f9b0919dc16ea83a8826e8d52b02178b38.tar.gz
v0.7.1
- Added: afserver certificate storing and checking - Modified: generating keys and certificate - Fixed: creating apf directory - Fixed: some bugs in proxy tunnel initialization
Diffstat (limited to 'src/server_get.c')
-rw-r--r--src/server_get.c67
1 files changed, 59 insertions, 8 deletions
diff --git a/src/server_get.c b/src/server_get.c
index 7ada39c..5066f54 100644
--- a/src/server_get.c
+++ b/src/server_get.c
@@ -22,28 +22,79 @@
#include "server_get.h"
#include <stdlib.h>
+#include <errno.h>
int
get_new_socket(int sockfd, char type, struct sockaddr *addr, socklen_t *addrlen, char* tunneltype)
{
int tmp;
+ int n, i;
switch (type) {
case 0: {
return accept(sockfd, addr, addrlen);
break;
}
case 1: {
- if (read(sockfd, &tmp, 4) != 4) {
- return -1;
+ i = 0;
+ while (i < 4) {
+ if ((n = read(sockfd, &tmp+i, 4-i)) != (4-i)) {
+ sleep(2);
+ if ((n > 0) && (n < 4)) {
+ i += n;
+ continue;
+ }
+ if ((n == -1) && (errno == EAGAIN)) {
+ continue;
+ }
+ return -1;
+ }
+ else {
+ break;
+ }
}
- if (read(sockfd, tunneltype, 1) != 1) {
- return -1;
+ i = 0;
+ while (i < 1) {
+ if ((n = read(sockfd, tunneltype+i, 1-i)) != (1-i)) {
+ if ((n == -1) && (errno == EAGAIN)) {
+ continue;
+ }
+ return -1;
+ }
+ else {
+ break;
+ }
}
- if (read(sockfd, addrlen, 4) != 4) {
- return -1;
+ i = 0;
+ while (i < 4) {
+ if ((n = read(sockfd, addrlen+i, 4-i)) != (4-i)) {
+ if ((n > 0) && (n < 4)) {
+ i += n;
+ continue;
+ }
+ if ((n == -1) && (errno == EAGAIN)) {
+ continue;
+ }
+ return -1;
+ }
+ else {
+ break;
+ }
}
- if (read(sockfd, addr, *addrlen) != *addrlen) {
- return -1;
+ i = 0;
+ while (i < *addrlen) {
+ if ((n = read(sockfd, addr+i, (*addrlen)-i)) != ((*addrlen)-i)) {
+ if ((n > 0) && (n < *addrlen)) {
+ i += n;
+ continue;
+ }
+ if ((n == -1) && (errno == EAGAIN)) {
+ continue;
+ }
+ return -1;
+ }
+ else {
+ break;
+ }
}
return tmp;
break;