|
|
@ -329,7 +329,7 @@ g_getchar(void)
|
|
|
|
int APP_CC
|
|
|
|
int APP_CC
|
|
|
|
g_tcp_set_no_delay(int sck)
|
|
|
|
g_tcp_set_no_delay(int sck)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
int ret = 1 ; /*error*/
|
|
|
|
int ret = 1; /* error */
|
|
|
|
#if defined(_WIN32)
|
|
|
|
#if defined(_WIN32)
|
|
|
|
int option_value;
|
|
|
|
int option_value;
|
|
|
|
int option_len;
|
|
|
|
int option_len;
|
|
|
@ -347,10 +347,10 @@ g_tcp_set_no_delay(int sck)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
option_value = 1;
|
|
|
|
option_value = 1;
|
|
|
|
option_len = sizeof(option_value);
|
|
|
|
option_len = sizeof(option_value);
|
|
|
|
if(setsockopt(sck, IPPROTO_TCP, TCP_NODELAY, (char*)&option_value,
|
|
|
|
if (setsockopt(sck, IPPROTO_TCP, TCP_NODELAY, (char*)&option_value,
|
|
|
|
option_len)==0)
|
|
|
|
option_len) == 0)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
ret = 0 ; /* success */
|
|
|
|
ret = 0; /* success */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -366,7 +366,7 @@ g_tcp_set_no_delay(int sck)
|
|
|
|
int APP_CC
|
|
|
|
int APP_CC
|
|
|
|
g_tcp_set_keepalive(int sck)
|
|
|
|
g_tcp_set_keepalive(int sck)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
int ret = 1 ; /*error*/
|
|
|
|
int ret = 1; /* error */
|
|
|
|
#if defined(_WIN32)
|
|
|
|
#if defined(_WIN32)
|
|
|
|
int option_value;
|
|
|
|
int option_value;
|
|
|
|
int option_len;
|
|
|
|
int option_len;
|
|
|
@ -384,10 +384,10 @@ g_tcp_set_keepalive(int sck)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
option_value = 1;
|
|
|
|
option_value = 1;
|
|
|
|
option_len = sizeof(option_value);
|
|
|
|
option_len = sizeof(option_value);
|
|
|
|
if(setsockopt(sck, SOL_SOCKET, SO_KEEPALIVE, (char*)&option_value,
|
|
|
|
if (setsockopt(sck, SOL_SOCKET, SO_KEEPALIVE, (char*)&option_value,
|
|
|
|
option_len)==0)
|
|
|
|
option_len) == 0)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
ret = 0 ; /* success */
|
|
|
|
ret = 0; /* success */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -1124,42 +1124,46 @@ g_obj_wait(tbus* read_objs, int rcount, tbus* write_objs, int wcount,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
FD_ZERO(&rfds);
|
|
|
|
FD_ZERO(&rfds);
|
|
|
|
FD_ZERO(&wfds);
|
|
|
|
FD_ZERO(&wfds);
|
|
|
|
/*Find the highest descriptor number in read_obj */
|
|
|
|
/* Find the highest descriptor number in read_obj */
|
|
|
|
if(read_objs!=NULL){
|
|
|
|
if (read_objs!=NULL)
|
|
|
|
|
|
|
|
{
|
|
|
|
for (i = 0; i < rcount; i++)
|
|
|
|
for (i = 0; i < rcount; i++)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
sck = (int)(read_objs[i]);
|
|
|
|
sck = (int)(read_objs[i]);
|
|
|
|
if (sck > 0) {
|
|
|
|
if (sck > 0)
|
|
|
|
|
|
|
|
{
|
|
|
|
FD_SET(sck, &rfds);
|
|
|
|
FD_SET(sck, &rfds);
|
|
|
|
if (sck > max)
|
|
|
|
if (sck > max)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
max = sck; /*max holds the highest socket/descriptor number */
|
|
|
|
max = sck; /* max holds the highest socket/descriptor number */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(rcount>0)
|
|
|
|
else if (rcount>0)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
g_writeln("Programming error read_objs is null");
|
|
|
|
g_writeln("Programming error read_objs is null");
|
|
|
|
return 1; /*error*/
|
|
|
|
return 1; /* error */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(write_objs!=NULL){
|
|
|
|
if (write_objs!=NULL)
|
|
|
|
|
|
|
|
{
|
|
|
|
for (i = 0; i < wcount; i++)
|
|
|
|
for (i = 0; i < wcount; i++)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
sck = (int)(write_objs[i]);
|
|
|
|
sck = (int)(write_objs[i]);
|
|
|
|
if (sck > 0) {
|
|
|
|
if (sck > 0)
|
|
|
|
|
|
|
|
{
|
|
|
|
FD_SET(sck, &wfds);
|
|
|
|
FD_SET(sck, &wfds);
|
|
|
|
if (sck > max)
|
|
|
|
if (sck > max)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
max = sck; /*max holds the highest socket/descriptor number */
|
|
|
|
max = sck; /* max holds the highest socket/descriptor number */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(wcount>0)
|
|
|
|
else if (wcount > 0)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
g_writeln("Programming error write_objs is null");
|
|
|
|
g_writeln("Programming error write_objs is null");
|
|
|
|
return 1; /*error*/
|
|
|
|
return 1; /* error */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
res = select(max + 1, &rfds, &wfds, 0, ptime);
|
|
|
|
res = select(max + 1, &rfds, &wfds, 0, ptime);
|
|
|
|
if (res < 0)
|
|
|
|
if (res < 0)
|
|
|
@ -1172,7 +1176,7 @@ g_obj_wait(tbus* read_objs, int rcount, tbus* write_objs, int wcount,
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 1; /*error*/
|
|
|
|
return 1; /* error */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
@ -1632,7 +1636,8 @@ g_strdup(const char* in)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
len = g_strlen(in);
|
|
|
|
len = g_strlen(in);
|
|
|
|
p = (char*)g_malloc(len + 1, 0);
|
|
|
|
p = (char*)g_malloc(len + 1, 0);
|
|
|
|
if (p != NULL) {
|
|
|
|
if (p != NULL)
|
|
|
|
|
|
|
|
{
|
|
|
|
g_strcpy(p, in);
|
|
|
|
g_strcpy(p, in);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return p;
|
|
|
|
return p;
|
|
|
@ -1652,9 +1657,9 @@ g_strndup(const char* in, const unsigned int maxlen)
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
len = g_strlen(in);
|
|
|
|
len = g_strlen(in);
|
|
|
|
if(len>maxlen)
|
|
|
|
if (len>maxlen)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
len = maxlen-1 ;
|
|
|
|
len = maxlen - 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
p = (char*)g_malloc(len + 2, 0);
|
|
|
|
p = (char*)g_malloc(len + 2, 0);
|
|
|
|
if (p != NULL)
|
|
|
|
if (p != NULL)
|
|
|
|