PDA

View Full Version : Timed out in Do_Get_Socket_String


Arachno331
11-16-2007, 08:53 AM
Socket Connection timed out in Do_Get_Socket_String

Whenever my applet loads on my site, the above error is logged.

Below is the function:

/************************************************************************
/
/ FUNCTION NAME: Do_get_socket_string(struct client_t *c, void *the_data, size_t the_size)
/
/ FUNCTION: reads the next packet type off the socket
/
/ AUTHOR: Brian Kelly, 4/23/99
/
/ ARGUMENTS:
/ int the_socket - the socket to read the packet type
/
/ RETURN VALUE:
/ int - the type of packet next on the socket
/
/ MODULES CALLED: wmove(), _filbuf(), clearok(), waddstr(), wrefresh(),
/ wclrtoeol()
/
/ DESCRIPTION:
/ Read a string from the keyboard.
/
/************************************************************************/

int Do_get_socket_string(struct client_t *c, char *theString, size_t theSize)
{
size_t theLength;
char string_buffer[SZ_LINE], error_msg[SZ_ERROR_MESSAGE + SZ_OUT_BUFFER];
sigset_t sigMask;
int theSignal;

/* prepare to unblock SIGIO */
sigemptyset(&sigMask);
sigaddset(&sigMask, SIGIO);
sigaddset(&sigMask, SIGALRM);

for (;;) {

/* if the socket is down, return an error */
if (!c->socket_up) {
return S_ERROR;
}

/* if we have information in the buffer */
if (c->in_buffer_size) {

/* see if the entire string has been downloaded */
theLength = strlen(c->in_buffer);

if (theLength < c->in_buffer_size) {

/* check that the passed pointer can handle the size */
if (theSize - 1 < theLength) {

/* log the error */
sprintf(error_msg, "[%s] Client returned a string of %d bytes, %d max in Do_get_socket_string.\n", c->connection_id, theLength, theSize);

Do_log_error(error_msg);

/* get as much of the string as we can */
strncpy(theString, c->in_buffer, theSize - 1);
theString[theSize - 1] = '\0';
}
else {
strcpy(theString, c->in_buffer);
}

/* add the terminating null to the string */
++theLength;

/* move up information in the buffer */
if (theLength < c->in_buffer_size) {
c->in_buffer_size -= theLength;
memmove(c->in_buffer, &c->in_buffer[theLength],
c->in_buffer_size);
}
else {
c->in_buffer_size = 0;
}

#ifdef RECEIVE_DEBUG
sprintf(error_msg, "[%s] received %d bytes\n",
c->connection_id, theLength);

Do_log(DEBUG_LOG, error_msg);
#endif

#ifdef RECEIVE_PACKET_DEBUG
sprintf(error_msg, "[%s] (%s)\n", c->connection_id, theString);
Do_log(DEBUG_LOG, error_msg);
#endif

return S_NORM;
}

/* the the buffer is maxed and we're here,
the string is too large for the buffer */

if (c->in_buffer_size == SZ_IN_BUFFER) {

sprintf(error_msg, "[%s] Request for a string, %d bytes, larger than buffer in Do_get_socket_string.\n", c->connection_id, theLength);

Do_log_error(error_msg);

c->socket_up = FALSE;
return S_ERROR;
}
}

/* We need to wait for information, so pause */
if (c->socket_up) {

#ifdef SUSPEND_DEBUG
sprintf(error_msg,
"[%s] now sleeping with alarm set for %d seconds.\n",
c->connection_id, c->timeout);

Do_log(DEBUG_LOG, error_msg);
#endif
sigwait(&sigMask, &theSignal);

#ifdef SUSPEND_DEBUG
sprintf(error_msg, "[%s] awoken on signal %d.\n",
c->connection_id, theSignal);

Do_log(DEBUG_LOG, error_msg);
#endif
/*
sleep(.1);
*/

}
else {
theSignal = SIGIO;
}

/* check events and the socket on a SIGIO */
if (theSignal == SIGIO) {

/* if the socket is up, we have room in the buffer and
there is info waiting */

if (c->socket_up && c->in_buffer_size < SZ_IN_BUFFER &&
Do_check_socket(c->socket)) {

Do_read_socket(c);
}

/* see if any other threads have sent us an event */
Do_check_events_in(c);
}

/* see if the tread alarm went off */
else if (theSignal == SIGALRM) {
/*
if (time(NULL) > c->timeoutAt) {
*/

switch(++c->timeoutFlag) {

/* alarm has gone off once */
case 1:
Do_send_int(c, PING_PACKET);
Do_send_buffer(c);

/* give the client 15 seconds to respond */
alarm(15);
c->timeoutAt = time(NULL) + 15;
break;

/* gone off twice */
case 2:

sprintf(error_msg, "[%s] Socket connection timed out.\n",
c->connection_id);

Do_log(CONNECTION_LOG, error_msg);
Do_send_error(c, "The socket connection timed out.\n");
Do_send_buffer(c);

/* assume the network connection is down */
sprintf(error_msg,
"[%s] Socket connection timed out in Do_get_socket_string.\n",
c->connection_id);

Do_log_error(error_msg);
c->socket_up = FALSE;
return S_ERROR;
}
}

/* unknown signal */
else {
sprintf(error_msg, "[%s] Received unknown signal %d.\n",
c->connection_id, theSignal);

Do_log_error(error_msg);
}
}
}

Arachno331
11-16-2007, 07:06 PM
No one can help me? :(

Arachno331
11-16-2007, 09:04 PM
Please someone - Help! I'd really appreciate it.

Arachno331
11-17-2007, 10:09 AM
Im pulling me hair out here! Please - Someone help me!

Active X
11-19-2007, 10:22 AM
Hey ! cool down and relax .

I think you've not been to the appropriate room . You must ask this question in Java forum above the Computer programming

;-)