Yu,Hua Qing vision embedded college lecturer.
spark network timeout
In network communication, many operations will cause process blocking. In this case, we need to set the time and forcibly return the result after the time to avoid infinite blocking of the process without data.
network timeout
Here we will summarize three methods for network timeout Detection:revelation online network connection timeout
sirius network timeout
Set the socket property so_rcvtimeo through setsockopt
Struct timeval T = {5, 0}
If (setsockopt (listenfd, sol_socket, so_rcvtimeo, & T, sizeof (t) =-1 ){
Perror ("setsockopt ");
Return-1;
}
Memset (& peeraddr, 0, sizeof (peeraddr ));
Len = sizeof (peeraddr );
If (connfd = accept (listenfd, (struct sockaddr *) & peeraddr, & Len) =-1 ){
Printf ("errno = % d: % s \ n", errno, strerror (errno ));
If (errno = eagain ){
Printf ("timeout \ n ");
Return-1;
}
}
2. Set a parameter of the select function for timeout Processing
Struct timeval T = {3, 0 };
While (1 ){
......
T. TV _sec = 3;
T. TV _usec = 0;
If (ret = select (maxfd + 1, & RDFS, null, null, & T) =-1 ){
Perror ("select ");
Return-1;
}
......
}
3. Set a timer to capture the sigalrm signal for time-out control
timeout or other network error
Struct sigaction Act;
Sigaction (sigalrm, null, & Act); // gets the sigalrm signal attribute
Act. sa_handler = handler; // sets the processing function of the sigalrm signal.
Sigaction (sigalrm, & act, null); // you can specify the sigalrm signal attribute.
Alarm (3); // set the timer to 3 seconds
While (1 ){
If (connfd = accept (listenfd, (struct sockaddr *) & peeraddr, & Len) =-1 ){
If (errno = eintr ){
Printf ("timeout \ n ");
Return-1;
}
}
If no data arrives within 3 seconds after the timer, the kernel generates a sigalrm signal to interrupt the current operation. We know that the signal capturing function can be set using the signal function or the sigaction function. However, only the sigaction function can be used here, because the interrupted operation will be re-executed after the signal processing function set by signal is executed.
how to fix nba live mobile network timeout
This article from the "embedded learning world" blog, please be sure to keep this source http://farsight.blog.51cto.com/1821374/1563349
Three methods for network timeout Detection