fix a bug on OS X 10.6.x

This commit is contained in:
Max Lv
2013-05-18 18:43:16 +08:00
parent 8649aeae3e
commit 70ddd012e3
6 changed files with 26 additions and 9 deletions
+9 -3
View File
@@ -645,7 +645,9 @@ static int process_worker(int in_fd, int out_fd) {
if (!have_death_sig) {
fd_set fds;
struct timeval tv = { 0, 5000000 };
struct timeval tv;
tv.tv_usec = 500000;
tv.tv_sec = 0;
FD_ZERO(&fds);
FD_SET(in_fd, &fds);
@@ -699,13 +701,17 @@ static void* thread_worker(void *p) {
if (!asyncns->dead) {
fd_set fds;
struct timeval tv = { 0, 5000000 };
struct timeval tv;
tv.tv_usec = 500000;
tv.tv_sec = 0;
FD_ZERO(&fds);
FD_SET(in_fd, &fds);
if (select(in_fd+1, &fds, NULL, NULL, &tv) < 0)
if (select(in_fd+1, &fds, NULL, NULL, &tv) < 0) {
perror("test");
break;
}
}
if (length < 0 &&
+1 -1
View File
@@ -11,7 +11,7 @@
static char *to_string(const json_value *value) {
if (value->type == json_string) {
return strndup(value->u.string.ptr, value->u.string.length);
return ss_strndup(value->u.string.ptr, value->u.string.length);
} else if (value->type == json_integer) {
return strdup(itoa(value->u.integer));
} else if (value->type == json_null) {
+2 -2
View File
@@ -699,9 +699,9 @@ int main (int argc, char **argv) {
listen_ctx.remote_host = malloc(sizeof(char *) * remote_num);
while (remote_num > 0) {
int index = --remote_num;
listen_ctx.remote_host[index] = strdup(remote_host[index]);
listen_ctx.remote_host[index] = remote_host[index];
}
listen_ctx.remote_port = strdup(remote_port);
listen_ctx.remote_port = remote_port;
listen_ctx.timeout = atoi(timeout);
listen_ctx.fd = listenfd;
listen_ctx.iface = iface;
+2 -2
View File
@@ -624,9 +624,9 @@ int main (int argc, char **argv) {
listen_ctx.remote_host = malloc(sizeof(char *) * remote_num);
while (remote_num > 0) {
int index = --remote_num;
listen_ctx.remote_host[index] = strdup(remote_host[index]);
listen_ctx.remote_host[index] = remote_host[index];
}
listen_ctx.remote_port = strdup(remote_port);
listen_ctx.remote_port = remote_port;
listen_ctx.timeout = atoi(timeout);
listen_ctx.fd = listenfd;
+11 -1
View File
@@ -43,6 +43,17 @@ char *itoa(int i) {
return p;
}
char *ss_strndup(const char *s, size_t n) {
size_t len = strlen(s);
char *ret;
if (len <= n) return strdup(s);
ret = malloc(n + 1);
strncpy(ret, s, n);
ret[n] = '\0';
return ret;
}
void FATAL(const char *msg) {
LOGE("%s", msg);
@@ -109,6 +120,5 @@ void demonize(const char* path) {
close(STDIN_FILENO);
close(STDOUT_FILENO);
close(STDERR_FILENO);
}
+1
View File
@@ -35,5 +35,6 @@ void ERROR(const char *s);
void usage(void);
void demonize(const char* path);
char *itoa(int i);
char *ss_strndup(const char *s, size_t n);
#endif // _UTILS_H