Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
S

SRIVATHSAN VIJAYA

@SRIVATHSAN VIJAYA
About
Posts
3
Topics
2
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • CloseHandle() freezes the program...
    S SRIVATHSAN VIJAYA

    Hi, Even I face the same problem when i try to close the handle. I haven't used any thread to create or close the handle. I have literally used CreateFileW() to create a handle for serial port communication.

    hComm = CreateFileW (pcCommPort, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);

    Where pcCommPort is "COM_2" CreateFileW call succeeds even if device is not connected. I have send few commands through WriteFile() and read ReadFile() api's and tried to close the handle using

    CloseHandle(hComm)

    But my application hangs infinitely. What would be the exact root cause for this issue? Sample:

    While(1)
    {
    i = 0;
    hComm = CreateFileW (pcCommPort, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
    while(i < 10)
    {
    i++;
    WriteFile(hComm , &txBuffer[0], numBytesToTx, (DWORD*)&numBytesTx, NULL);
    ReadFile(hComm , &get_data[i], 1, (DWORD*)&numBytesRx, NULL);
    }
    CloseHandle(hComm);
    hComm = NULL;
    }

    C / C++ / MFC json help tutorial question

  • Multiple Client Support Server Application designed with Windows Named Pipes hangs frequently
    S SRIVATHSAN VIJAYA

    Initially we have designed a client server model with named pipes. Where Server is capable of handling only one client. We expanded the server to hold 4 client instances at a time. After which application hangs frequently while connection is established between client and Server. Added the code snippet below. Please look at the snippet and suggest Is it a right method to handle multiple clients. //Client.c rhPipe = CreateFile("\\\\.\\Pipe\\Send", GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL); if(rhPipe == INVALID_HANDLE_VALUE) { rhPipe = NULL; return; } whPipe = CreateFile("\\\\.\\Pipe\\Recv", GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL); if(whPipe == INVALID_HANDLE_VALUE) { whPipe = NULL; return; } char message[512]; char buffer[1024]; BOOL writeStatus = FALSE; BOOL bResult = FALSE; DWORD cbBytes = 0; COMMTIMEOUTS cto; cto.ReadIntervalTimeout = 5; cto.ReadTotalTimeoutConstant = 5*1000; SetCommTimeouts(rhPipe, &cto); while(1) { memset(message,0,sizeof(message)); strcpy(message,"Message From Client.... !!!"); writeStatus = FALSE; cbBytes = 0; writeStatus = WriteFile(whPipe, message, sizeof(message), &cbBytes, NULL); if(writeStatus == FALSE || cbBytes != sizeof((message)) { return; } memset(&buffer,0,sizeof(buffer)); bResult = ReadFile(rhPipe, &buffer, 1024, &cbBytes, NULL); if(bResult == TRUE) { if(cbBytes == 0 ) printf("Receive from Pipe Timeout.... \n"); else { printf("Data Received From Server...: %s\n,buffer); } } else { if(GetLastError() != 0) { CloseHandle(rhPipe); CloseHandle(whPipe); return; } } } //Server.c typedef struct { OVERLAPPED oOverlap; HANDLE hPipeInst; CHAR chRequest[BUFFER_SIZE]; DWORD cbRead; TCHAR chReply[BUFFER_SIZE]; DWORD cbToWrite; DWORD dwState; BOOL fPendingIO; int processId; } PIPEINST, *LPPIPEINST; #define RECEIVING_PIPE 0 #define TRANSMITTING_PIPE 1 #define INSTANCES 4 PIPEINST Pipe[INSTANCES]; HANDLE hEvents[INSTANCES]; int CreateIPCPipe(int option) { char log_buf[512]; switch(option) { case RECEIVING_PIPE: { int i; for (i = 0; i < INSTANCES; i++) { hEvents[i] = CreateEvent(NULL,TRUE,FALSE, NULL); if (hEvents[i] == NULL) { return 0; } Pipe[i].oOverlap.hEvent = hEvents[i]; Pipe[i].hPipeInst = CreateNamedPipe("\\\\.\\Pipe\\Recv", PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED, PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PI

    Windows API sysadmin

  • Multiple Client Support Server Application designed with Named Pipes hangs frequently
    S SRIVATHSAN VIJAYA

    Initially we have designed a client server model with named pipes. Where Server is capable of handling only one client. We expanded the server to hold 4 client instances at a time. After which application hangs frequently while connection is established between client and Server. Added the code snippet below. Please look at the snippet and suggest Is it a right method to handle multiple clients. //Client.c rhPipe = CreateFile("\\\\.\\Pipe\\Send", GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL); if(rhPipe == INVALID_HANDLE_VALUE) { rhPipe = NULL; return; } whPipe = CreateFile("\\\\.\\Pipe\\Recv", GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL); if(whPipe == INVALID_HANDLE_VALUE) { whPipe = NULL; return; } char message[512]; char buffer[1024]; BOOL writeStatus = FALSE; BOOL bResult = FALSE; DWORD cbBytes = 0; COMMTIMEOUTS cto; cto.ReadIntervalTimeout = 5; cto.ReadTotalTimeoutConstant = 5*1000; SetCommTimeouts(rhPipe, &cto); while(1) { memset(message,0,sizeof(message)); strcpy(message,"Message From Client.... !!!"); writeStatus = FALSE; cbBytes = 0; writeStatus = WriteFile(whPipe, message, sizeof(message), &cbBytes, NULL); if(writeStatus == FALSE || cbBytes != sizeof((message)) { return; } memset(&buffer,0,sizeof(buffer)); bResult = ReadFile(rhPipe, &buffer, 1024, &cbBytes, NULL); if(bResult == TRUE) { if(cbBytes == 0 ) printf("Receive from Pipe Timeout.... \n"); else { printf("Data Received From Server...: %s\n,buffer); } } else { if(GetLastError() != 0) { CloseHandle(rhPipe); CloseHandle(whPipe); return; } } } //Server.c typedef struct { OVERLAPPED oOverlap; HANDLE hPipeInst; CHAR chRequest[BUFFER_SIZE]; DWORD cbRead; TCHAR chReply[BUFFER_SIZE]; DWORD cbToWrite; DWORD dwState; BOOL fPendingIO; int processId; } PIPEINST, *LPPIPEINST; #define RECEIVING_PIPE 0 #define TRANSMITTING_PIPE 1 #define INSTANCES 4 PIPEINST Pipe[INSTANCES]; HANDLE hEvents[INSTANCES]; int CreateIPCPipe(int option) { char log_buf[512]; switch(option) { case RECEIVING_PIPE: { int i; for (i = 0; i < INSTANCES; i++) { hEvents[i] = CreateEvent(NULL,TRUE,FALSE, NULL); if (hEvents[i] == NULL) { return 0; } Pipe[i].oOverlap.hEvent = hEvents[i]; Pipe[i].hPipeInst = CreateNamedPipe("\\\\.\\Pipe\\Recv", PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED, PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PI

    C / C++ / MFC sysadmin
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups