Named Pipe problem again

This is a discussion on Named Pipe problem again within the C Programming forums, part of the General Programming Boards category; Hi guys, I posted a few years ago about a named pipe issue, and I am having the same problem ...

  1. #1
    Registered User
    Join Date
    Oct 2007
    Posts
    6

    Named Pipe problem again

    Hi guys,
    I posted a few years ago about a named pipe issue, and I am having the same problem again.

    So here is a quick description of what I am trying to do:

    I have a socket, where my process is waiting for either more incoming data coming to it, or waiting on outgoing data being ready via a named pipe. For this I am using a select on a named pipe, and on the socket, and both have been opened in non-blocking mode.

    Now, when i do the select, the named pipe fd always says unblocked, but the socket is fine, in that the select does not return. If I don't open the named pipe in non-blocking mode, then the open command for the named pipe will block itself, and I won't be able to wait for incoming socket data.

    What should I do?? Should opening/closing the named pipe for each select solve this?

    A second question about the write to the named pipe. i am also opening it in non-blocking mode, and then waiting on the select to pick up that there is data to be read. Would this work?

    This is quite urgent, so any help would be greatly appreciated.

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,762
    One of the things you could do is post some code so we can see what you're trying to do.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Oct 2007
    Posts
    6
    Ok, here it is:
    Code:
    void DUAL_Select(AUTH_IFE_STR *pAuth_Ife_Str)
    {
       fd_set readset;
       int  select_result,result;
       int named_pipe;
       int maxSOCK;
       char *envPATH;
       char nnamedPIPE[256];
       char buffer[8];
    
    
         named_pipe = open(nnamedPIPE, O_RDONLY | O_NONBLOCK);
            pAuth_Ife_Str->sread_named_pipe=named_pipe;
    
          FD_ZERO(&readset);
          FD_CLR(pAuth_Ife_Str->sread_named_pipe,&readset);
          FD_CLR(pAuth_Ife_Str->sSocketfd,&readset);
          FD_SET(pAuth_Ife_Str->sread_named_pipe,&readset);
          FD_SET(pAuth_Ife_Str->sSocketfd,&readset);
          if ((pAuth_Ife_Str->sSocketfd - pAuth_Ife_Str->sread_named_pipe) > 0)
          {
             maxSOCK = pAuth_Ife_Str->sSocketfd;
          }                                                                                                                          
          else
          {                                                                    
             maxSOCK = pAuth_Ife_Str->sread_named_pipe;
          }
          select_result = select(maxSOCK + 1, &readset, NULL, NULL, NULL);
       if (FD_ISSET(pAuth_Ife_Str->sread_named_pipe, &readset))
       {   
            FD_CLR(pAuth_Ife_Str->sread_named_pipe, &readset);
            bzero(buffer,8);
            result = read(pAuth_Ife_Str->sread_named_pipe,buffer,8);
    
       if (FD_ISSET(pAuth_Ife_Str->sSocketfd, &readset))
       {   
           FD_CLR(pAuth_Ife_Str->sSocketfd, &readset);
           //printf("Socket is ready for read\n");
           pAuth_Ife_Str->sSockReadAve = '1';
       };
    
       result = close (pAuth_Ife_Str->sread_named_pipe);
    When closing the socket each time, it does seem to be fine, but that is what I am having to do. Is that correct?

    What should I do when opening the npipe for write, open it in blocking or non-blocking mode?

  4. #4
    - - - - - - - - oogabooga's Avatar
    Join Date
    Jan 2008
    Posts
    2,808
    Just to make sure, you're real code isn't missing the brace on line 34, right?
    (And you have an extraneous semicolon on line 40.)

  5. #5
    Registered User
    Join Date
    Oct 2007
    Posts
    6
    Sorry, yes you are right, the ';' issues are to do with taking code fragments and pasting it here. Apologies...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Trouble with named pipe...
    By DamienCurr in forum C Programming
    Replies: 5
    Last Post: 03-27-2010, 10:49 PM
  2. Named pipe problem
    By rahul_c in forum C Programming
    Replies: 3
    Last Post: 10-02-2007, 06:40 PM
  3. Named Pipe Problems.
    By Mastadex in forum Windows Programming
    Replies: 2
    Last Post: 06-16-2006, 09:35 AM
  4. named pipe problem
    By fnoyan in forum Linux Programming
    Replies: 0
    Last Post: 05-28-2006, 06:54 AM
  5. Having trouble with a named pipe
    By crazeinc in forum C Programming
    Replies: 2
    Last Post: 05-13-2005, 02:00 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21