Announcement

Collapse
No announcement yet.

eth0 link down, link up

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • dreuu
    replied
    Works!

    Thanks scook! It seems to work!

    I need to set up both vaules to avoid the delay: SO_SNDTIMEO & SO_RCVTIMEO. If I just set up SO_SNDTIMEO the delay continues.

    But now it works and the timeout is exactly 5sec in the TLOG:

    Code:
    216 E ../final.c    324 Comprobando errores de 1                       00:13:57
    217 E ../final.c    330 Trama con error                                00:13:57
    218 E ../final.c    337 C241310001/000/036/65376/000/09F               00:13:57
    219 E ../final.c    347 socket realizado...                            00:13:57
    220 E ../final.c    370 Error al conectar...                           00:14:02
    221 E ../final.c    337 C241310001/000/036/65376/000/10F               00:14:02
    222 E ../final.c    347 socket realizado...                            00:14:02
    223 E ../final.c    370 Error al conectar...                           00:14:07
    224 E ../final.c    337 C241310001/000/036/65376/000/11F               00:14:07
    225 E ../final.c    347 socket realizado...                            00:14:07
    226 E ../final.c    370 Error al conectar...                           00:14:12
    227 E ../final.c    337 C241310001/000/036/65376/000/36F               00:14:12
    228 E ../final.c    347 socket realizado...                            00:14:12
    229 E ../final.c    370 Error al conectar...                           00:14:17
    230 E ../final.c    898 ERROR al enviar                                00:14:17
    Thanks!

    Leave a comment:


  • dreuu
    replied
    Wow...

    Wow...thanks scook! It seems that I was really wrong!

    I don't understand why it worked when I changed TCP_MAXSEG but, anyway, I will try this tomorrow.

    Keep you informed. Thanks.

    Leave a comment:


  • scook
    replied
    Socket options

    TCP_MAXSEG is the maximum segment size in bytes; it does not measure time.

    SO_SNDTIMEO and SO_RCVTIMEO must be passed a struct timeval; the struct has seconds and microseconds fields which must both be filled in:

    static bool etTimeout(
    int sock, uint32_t timeoutMilliseconds, int sockOption
    )
    {
    struct timeval tv;
    if(timeoutMilliseconds == TIME_WAIT_FOREVER)
    {
    tv.tv_sec = -1;
    tv.tv_usec = -1;
    }
    else
    {
    tv.tv_sec = timeoutMilliseconds/1000;
    tv.tv_usec = (timeoutMilliseconds%1000)*1000;
    }
    if(setsockopt(sock, SOL_SOCKET, sockOption, &tv, sizeof(tv)) < 0)
    {
    return false;
    }
    return true;
    }

    Leave a comment:


  • dreuu
    replied
    Moving fordward...

    Well... it seems that I've made some progress:

    Regarding the connect() delay it seems that it is related to the TCP connection timeout. So I've changed the value TCP_MAXSEG and seems to work: now enters the failure condition:

    Code:
    int option;
    option=5;
    setsockopt(sock,IPPROTO_TCP,TCP_MAXSEG,&option,sizeof(option));
    I'm also changing the values for sending and receiving data but have some doubts:

    Code:
    option=5000;
    setsockopt(sock,SOL_SOCKET,SO_SNDTIMEO,&option,sizeof(option));
    setsockopt(sock,SOL_SOCKET,SO_RCVTIMEO,&option,sizeof(option));
    1- Is the time for TCP_MAXSEG especified in seconds and the time for SO_SNDTIMEO and SO_RCVTIMEO in milliseconds??

    2- The timeout condition applies just to the connection or also to the full data sending procedure? I mean: If the socket connects, begins sending the info but there's so much info that it will take 10secs to complete, will it also timeout at 5000milliseconds even that the data is being sent?

    Thanks to all of you for your help!

    **Added: With the new value for SO_SNDTIMEO I'm always getting an error when using send!! Any idea?
    Last edited by dreuu; 09-29-2010, 02:14 PM. Reason: New error appeared with the code

    Leave a comment:


  • dreuu
    replied
    Working on it

    Today I will start trying this. Thanks for the answer. I'll keep you informed!

    Leave a comment:


  • eliska
    replied
    You probably want to set a timeout for the connection by changing the SO_RCVTIMEO value with setsockopt(). The default value is 4 minutes. After calling connect(), you can set it back to the default (or change it to yet a different value).
    Last edited by eliska; 09-13-2010, 07:51 PM. Reason: Clarification

    Leave a comment:


  • dreuu
    started a topic eth0 link down, link up

    eth0 link down, link up

    I have a program that works correctly, but I have the following question:

    When my program loses network or server is not, my program can not make the connect (). My program is a condition that if not detected then connect a set of instructions.

    Copy the code:

    Code:
    if (connect (sock, (struct sockaddr *) &servername, sizeof (servername)) == 0)
        {	  
    	    enviook=write_to_server (sock,envio);
    		if (enviook==true)
    		{
    			shutdown (sock, 2);
    			closesocket(sock);
    			for (i=0;i<=BLINK;i++)
    			{
    				led2=1;
    				led1=0;
    				CPMGroupSetValue("SampleIn", led2, true, errorCPM, NULL);
    				CPMGroupSetValue("SampleOut", led1, true, errorCPM, NULL);
    				TLOG(TLOG_SEVERITY_DEBUG, "LED AMARILLO");//led amarillo
    				DELAY_THREAD(0, DLY_MSECS, BLINK_TIME);
    				led2=0;
    				led1=0;
    				CPMGroupSetValue("SampleIn", led2, true, errorCPM, NULL);
    				CPMGroupSetValue("SampleOut", led1, true, errorCPM, NULL);
    				TLOG(TLOG_SEVERITY_DEBUG, "LED VERDE");//led verde
    				DELAY_THREAD(0, DLY_MSECS, BLINK_TIME);
    			}
    		}
    	} else
    	{
    		TLOG(TLOG_SEVERITY_ERR, "ERROR:No se ha podido conectar al servidor especificado ");
    		
    		char* str_message = sprintf_malloc("ERROR 2 sock=%d \n",  sock);
    		fwrite(str_message, 1, strlen(str_message), fp);
    		Free(str_message);
    		for (i=0;i<=BLINK;i++)
    		{
    			
    			led2=0;
    			led1=1;
    			CPMGroupSetValue("SampleIn", led2, true, errorCPM, NULL);
    			CPMGroupSetValue("SampleOut", led1, true, errorCPM, NULL);
    			TLOG(TLOG_SEVERITY_DEBUG, "LED NARANJA");//led naranja
    			DELAY_THREAD(0, DLY_MSECS, BLINK_TIME);
    			led2=1;
    			led1=1;
    			CPMGroupSetValue("SampleIn", led2, true, errorCPM, NULL);
    			CPMGroupSetValue("SampleOut", led1, true, errorCPM, NULL);
    			TLOG(TLOG_SEVERITY_DEBUG, "LED ROJO");//led rojo
    			DELAY_THREAD(0, DLY_MSECS, BLINK_TIME);
    		}
    	}
    In tlog functions as it does I can see the following lines:
    eth0 link down
    eth0 link up

    Someone knows because not within the "else" in the connect, my program?

    Thank you very much,

    Carlos
Working...
X