In transplant a program from Windows to Linux under problems,
Program is a middleware, running under Windows, ported to Linux is a problem, is a client server roughly information interact through the middleware, the program USES the socket communication, after then start can invoke the service call is successful, but after a few calls program crash,
Check the core file, it is
The Program terminated with signal 11, Segmentation fault.
# 0 0 x00002b05482a70dd in vfprintf () the from/lib64/libc. So. 6
After using the bt command
# 0 0 x00002b05482a70dd in vfprintf () the from/lib64/libc. So. 6
# 1 0 x00002b05482c5af9 in vsprintf () the from/lib64/libc. So. 6
,,, (the ellipsis is a heap of repeated content about some dynamic library library file, there are thousands of)
Last lines sometimes display near the select function code, sometimes display near the accept function code, and then corresponding function returns is - 1.
Client packaged good, should be no problem, now put the accept and the select function is roughly labeled, the great god, please help me to analyze problem, that is what went from
The accept function is roughly as follows:
# ifdef WIN32
Int iAddrLen;
# the else
Unsigned long iAddrLen;
# endif
While (WaitForSingleObject (ExitSocket, 10)==WAIT_TIMEOUT)//WaitForSingleObject made corresponding implementation under Linux
{
Memset (& amp; ClientAddr, 0, sizeof (sockaddr_in));
IAddrLen=sizeof (sockaddr_in);
# ifdef WIN32
NewSocket=accept (m_ListenSocket, (sockaddr *) & amp; ClientAddr, & amp; IAddrLen);
# the else
NewSocket=accept (m_ListenSocket, (sockaddr *) & amp; ClientAddr, (socklen_t *) & amp; IAddrLen);
# endif
If (NewSocket==INVALID_SOCKET)
{
# # ifndef WIN32
If (WSAGetLastError ()==EINTR)
{
continue;
}
The else {
Printf (" accept fail. ");
}
# the else
Printf (" accept failed, err=% d. \ n ", WSAGetLastError ());
continue;
# endif
}
The else
{
Printf (" accept ok, NewSocket=% d. \ n ", NewSocket);
}
The select function is roughly as follows:
While (WaitForSingleObject (ExitSocket, 0)==WAIT_TIMEOUT) {//the WaitForSingleObject function has already made a corresponding implementation under Linux
.//initialize the socket
.//set the timeout value
.//set the socket
IRet=select (64, & amp; Readfds, & amp; Writefds, & amp; Exceptfds, & amp; Seltime);
If (iRet & lt; 1)
{
Sleep (1);//here also have a corresponding use of sleep and the realization of the usleep
continue;
}
.//to the judgment of the data and processing functions
}
Because the socket programming is not a lot of contact, don't know how that could have an error in the accept or select place, understand, please help me have a look at what's going on, thank you,