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
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Extending named server overlapped IO

Extending named server overlapped IO

Scheduled Pinned Locked Moved C / C++ / MFC
sysadminhardwaredata-structurescryptographybusiness
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    venkat swaminathan
    wrote on last edited by
    #1

    I am trying to implement a service provider to connect with a hardware device. request some suggestion on my approach and ideas to implement a robust system. Mentioned are the raised requirements 0. Receive data from other EXE process 1. To process received Q information. 2. Asynchronously send information on some failure. TO implement the mentioned system: 1. Selected 2 named pipe (commandRecv & commandSend) 2. CommandRecv pipe will be used as "Named Pipe Server Using Overlapped" I/O" 3. commandSend pipe will be used for sending the processed information. 4. commandSend will also need to send all the async messages from service provider to connected application. On init system will create a thread to hold connection instance of commandSend pipe.After creating thread instance commandRecv pipe will be set to overlapped I/O mode and process recieve queue information.

    This is the code which i am trying to extend:

    <pre>#include <windows.h>
    #include <stdio.h>
    #include <tchar.h>
    //#include <strsafe.h>

    //#include <glib.h>

    #define CONNECTING_STATE 0
    #define READING_STATE 1
    #define WRITING_STATE 2
    #define INSTANCES 4
    #define PIPE_TIMEOUT 5000
    #define BUFSIZE 4096

    typedef struct
    {
    OVERLAPPED oOverlap;
    HANDLE hPipeInst;
    TCHAR chRequest[BUFSIZE];
    DWORD cbRead;
    TCHAR chReply[BUFSIZE];
    DWORD cbToWrite;
    DWORD dwState;
    BOOL fPendingIO;
    int processId;
    } PIPEINST, *LPPIPEINST;

    typedef struct
    {
    char appName[256];
    int processId;
    }PIPEHANDSHAKE;

    VOID DisconnectAndReconnect(DWORD);
    BOOL ConnectToNewClient(HANDLE, LPOVERLAPPED);
    VOID GetAnswerToRequest(LPPIPEINST);

    PIPEINST Pipe[INSTANCES];
    HANDLE hEvents[INSTANCES];

    HANDLE responsePipeHandle[INSTANCES];

    DWORD WINAPI InstanceThread(LPVOID);

    HANDLE hPipeHandles[10];
    PULONG s;

    LPTSTR lpszPipename = TEXT("\\\\.\\pipe\\mynamedpipe");
    LPTSTR lpszResponsePipe = TEXT("\\\\.\\pipe\\mynamedpipe1");

    //GHashTable* hash;

    int responsePipeConnectionHandler(VOID)
    {
    BOOL fConnected = FALSE;
    DWORD dwThreadId = 0;
    HANDLE hPipe = INVALID_HANDLE_VALUE, hThread = NULL;
    int cbBytesRead;
    INT threadCount=0;
    //hash = g_hash_table_new(g_str_hash, g_str_equal);
    char bufferSize[512];
    for (;;)
    {
    _tprintf( TEXT("\nPipe Server: Main thread awaiting client connection on %s\n"), lpszResponsePipe);
    hPipe = CreateNamedPipe(
    lpszResponsePipe,

    F 1 Reply Last reply
    0
    • V venkat swaminathan

      I am trying to implement a service provider to connect with a hardware device. request some suggestion on my approach and ideas to implement a robust system. Mentioned are the raised requirements 0. Receive data from other EXE process 1. To process received Q information. 2. Asynchronously send information on some failure. TO implement the mentioned system: 1. Selected 2 named pipe (commandRecv & commandSend) 2. CommandRecv pipe will be used as "Named Pipe Server Using Overlapped" I/O" 3. commandSend pipe will be used for sending the processed information. 4. commandSend will also need to send all the async messages from service provider to connected application. On init system will create a thread to hold connection instance of commandSend pipe.After creating thread instance commandRecv pipe will be set to overlapped I/O mode and process recieve queue information.

      This is the code which i am trying to extend:

      <pre>#include <windows.h>
      #include <stdio.h>
      #include <tchar.h>
      //#include <strsafe.h>

      //#include <glib.h>

      #define CONNECTING_STATE 0
      #define READING_STATE 1
      #define WRITING_STATE 2
      #define INSTANCES 4
      #define PIPE_TIMEOUT 5000
      #define BUFSIZE 4096

      typedef struct
      {
      OVERLAPPED oOverlap;
      HANDLE hPipeInst;
      TCHAR chRequest[BUFSIZE];
      DWORD cbRead;
      TCHAR chReply[BUFSIZE];
      DWORD cbToWrite;
      DWORD dwState;
      BOOL fPendingIO;
      int processId;
      } PIPEINST, *LPPIPEINST;

      typedef struct
      {
      char appName[256];
      int processId;
      }PIPEHANDSHAKE;

      VOID DisconnectAndReconnect(DWORD);
      BOOL ConnectToNewClient(HANDLE, LPOVERLAPPED);
      VOID GetAnswerToRequest(LPPIPEINST);

      PIPEINST Pipe[INSTANCES];
      HANDLE hEvents[INSTANCES];

      HANDLE responsePipeHandle[INSTANCES];

      DWORD WINAPI InstanceThread(LPVOID);

      HANDLE hPipeHandles[10];
      PULONG s;

      LPTSTR lpszPipename = TEXT("\\\\.\\pipe\\mynamedpipe");
      LPTSTR lpszResponsePipe = TEXT("\\\\.\\pipe\\mynamedpipe1");

      //GHashTable* hash;

      int responsePipeConnectionHandler(VOID)
      {
      BOOL fConnected = FALSE;
      DWORD dwThreadId = 0;
      HANDLE hPipe = INVALID_HANDLE_VALUE, hThread = NULL;
      int cbBytesRead;
      INT threadCount=0;
      //hash = g_hash_table_new(g_str_hash, g_str_equal);
      char bufferSize[512];
      for (;;)
      {
      _tprintf( TEXT("\nPipe Server: Main thread awaiting client connection on %s\n"), lpszResponsePipe);
      hPipe = CreateNamedPipe(
      lpszResponsePipe,

      F Offline
      F Offline
      Frankie C
      wrote on last edited by
      #2

      Why you can't use GetNamedPipeClientProcessId()? Your limit is not MingW-32, but your OS. This function isn't available on XP and below. If you're developing on VISTA and above be shure that the WINVER and _WIN32_WINNT are correctly set for VISTA or above see here. If you're developing on XP you're no luky, there is no way other than access file informations in kernel mode (you have to write a driver to do that).

      V 1 Reply Last reply
      0
      • F Frankie C

        Why you can't use GetNamedPipeClientProcessId()? Your limit is not MingW-32, but your OS. This function isn't available on XP and below. If you're developing on VISTA and above be shure that the WINVER and _WIN32_WINNT are correctly set for VISTA or above see here. If you're developing on XP you're no luky, there is no way other than access file informations in kernel mode (you have to write a driver to do that).

        V Offline
        V Offline
        venkat swaminathan
        wrote on last edited by
        #3

        Yup, you are tight , iwas jsut able to extend and use it directly... :)

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

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