Wed Mar 26 00:33:35 2014 3061871712 DEBUG Creating Thread (Thread.cpp:159:Thread)
Wed Mar 26 00:33:35 2014 3061871712 DEBUG Starting Thread (Thread.cpp:182:Start)
Wed Mar 26 00:33:35 2014 3061871712 DEBUG fvdw ok create thread (Thread.cpp:209:Start)
Wed Mar 26 00:33:35 2014 3061871712 DEBUG Accepting connection (Connection.cpp:454:Accept)
char* Connection::ReadLine(char* pBuffer, int iSize, int* pBytesRead)
{
if (m_eStatus != csConnected)
{
return NULL;
}
char* pBufPtr = pBuffer;
iSize--; // for trailing '0'
int iBytesRead = 0;
int iBufAvail = m_iBufAvail; // local variable is faster
char* szBufPtr = m_szBufPtr; // local variable is faster
while (iSize)
{
if (!iBufAvail)
{
iBufAvail = recv(m_iSocket, m_szReadBuf, CONNECTION_READBUFFER_SIZE, 0);
if (iBufAvail < 0)
{
ReportError("Could not receive data on socket", NULL, true, 0);
break;
}
else if (iBufAvail == 0)
{
break;
}
szBufPtr = m_szReadBuf;
m_szReadBuf[iBufAvail] = '\0';
}
int len = 0;
char* p = (char*)memchr(szBufPtr, '\n', iBufAvail);
if (p)
{
len = (int)(p - szBufPtr + 1);
}
else
{
len = iBufAvail;
}
if (len > iSize)
{
len = iSize;
}
// debug("fvdw readline 2");
usleep(100);
memmove(pBufPtr, szBufPtr, len);
// debug("fvdw realine 4");
pBufPtr += len;
szBufPtr += len;
iBufAvail -= len;
iBytesRead += len;
iSize -= len;
if (p)
{
break;
}
}
*pBufPtr = '\0';
m_iBufAvail = iBufAvail > 0 ? iBufAvail : 0; // copy back to member
m_szBufPtr = szBufPtr; // copy back to member
if (pBytesRead)
{
*pBytesRead = iBytesRead;
}
if (pBufPtr == pBuffer)
{
return NULL;
}
return pBuffer;
}
brinka123 wrote:No memory allocation problems seen?
The memcpy/memmve uses a pointer created by malloc...
By default, Linux follows an optimistic memory allocation strategy. This means that when malloc() returns non-NULL there is no guarantee that the memory really is available. In case it turns out that the system is out of memory, one or more processes will be killed by the OOM killer. For more information, see the description of /proc/sys/vm/overcommit_memory and /proc/sys/vm/oom_adj in proc(5), and the Linux kernel source file Documentation/vm/overcommit-accounting.
he out of memory can be a temporary, very short moment. Due to delays, problems don't have to occur.
Return to Lacie Network Space vs2 and max version
Users browsing this forum: Bing Bot and 11 guests