   Add Database logic to IOCPNet Server
  Dear All:I have downloaded the source code of the IOCPNetserver:http://www.codeproject.com/KB/IP/IOCPNet.aspxI want to know if i can add database logic to read and write data from clients in a database located in the server.Do I have to implement thread syncronization before read or write data to the database when using IOCP?I'm using the fisrt two examples in the IOCPNet page.Could you help me?Thanks.Alfredo Mendiola LoyolaLima, Perú   
Quote:Original post by mendiola_loyolaDo I have to implement thread syncronization before read or write data to the database when using IOCP?No, iff the database access *API* guarantees to be multi-threaded or reentrant.The rest of synchronization depends on business logic itself - does it require transactions, what guarantees does the database itself give, is there some implicit strict ordering of queries, how consistent must the state be at various points and similar.   ;Quote:Original post by AntheusQuote:Original post by mendiola_loyolaDo I have to implement thread syncronization before read or write data to the database when using IOCP?No, iff the database access *API* guarantees to be multi-threaded or reentrant.The rest of synchronization depends on business logic itself - does it require transactions, what guarantees does the database itself give, is there some implicit strict ordering of queries, how consistent must the state be at various points and similar.I understand that with IOCP I can write data to DB or files in themain MainLogic thread without problems.In this example i'm writing to disk the frame received from a client:///////////////////////////////////////////////////////////////////////////void abc(char *p){FILE *fp = fopen("c:\\ServerData.txt","a+");fprintf(fp,"%s\n",p);fclose(fp);}void MainLogic(OIOCPNet *pIOCPNet, DWORD SocketUnique, OBufferedSocket *pBuffSock, BYTE *pReadData, DWORD ReadSize){    printf("pReadData = %s\n", pReadData);  abc((char*)pReadData); //My code.    pIOCPNet-&gt;WriteData(SocketUnique, pBuffSock, pReadData, ReadSize); // echo.return;} // MainLogic()///////////////////////////////////////////////////////////////////////////Is IOCP thread safe?Or Do I have to use mutex, events to block threads.This code is uding just one thread "LogicThread"///////////////////////////////////////////////////////////////////////////DWORD WINAPI LogicThread(void *pParam){int iRes;OIOCPNet *pIOCPNet;int EventType;DWORD SocketUnique;BYTE *pReadData;DWORD ReadSize;OBufferedSocket *pBuffSock;OReadSlotElement *pSlot;void *pCustData; // for formatting. no custom data is used in this test.pIOCPNet = (OIOCPNet *)pParam;while (1 == InterlockedExchange((long *)&g_dRunning, g_dRunning)){iRes = pIOCPNet-&gt;GetSocketEventData(WAIT_TIMEOUT_TEST, &EventType, &SocketUnique, &pReadData, &ReadSize, &pBuffSock, &pSlot, &pCustData);if (RET_TIMEOUT == iRes){continue;}else if (RET_FAIL == iRes){return 0;}else if (RET_SOCKET_CLOSED == iRes){// release pCustData.continue;}// Process main logic.MainLogic(pIOCPNet, SocketUnique, pBuffSock, pReadData, ReadSize);pIOCPNet-&gt;ReleaseSocketEvent(pSlot);}return 0;} // LogicThread()///////////////////////////////////////////////////////////////////////////Thanks.Alfredo Mendiola LoyolaLima, Perú[Edit: Please use [source][/source] tags for large code pasts. - Washu]   