Jump to content

DosSetNmPipeSem: Difference between revisions

From EDM2
No edit summary
Ak120 (talk | contribs)
mNo edit summary
Line 1: Line 1:
{{Legacy
|RepFunc=
|Remarks=This page list the older version of the function for reference.
}}
This call attaches a system semaphore to a local named pipe.
This call attaches a system semaphore to a local named pipe.


==Syntax==
==Syntax==
  DosSetNmPipeSem (Handle, SemHandle, KeyHandle)  
  DosSetNmPipeSem (Handle, SemHandle, KeyHandle)


==Parameters==
==Parameters==
;Handle (HPIPE) - input : Handle of the named pipe returned by DosMakeNmPipe or DosOpen.
;Handle (HPIPE) - input : Handle of the named pipe returned by [[DosMakeNmPipe]] or DosOpen.
; SemHandle (HSEM) - input : A system semaphore handle that is cleared when the pipe (identified by Handle) has read data or write space available.
;SemHandle (HSEM) - input : A system semaphore handle that is cleared when the pipe (identified by Handle) has read data or write space available.
;KeyHandle (USHORT) - input : An arbitrary value that is used to associate named pipe actions with result codes in DosQNmPipeSemState.  
;KeyHandle (USHORT) - input : An arbitrary value that is used to associate named pipe actions with result codes in [[DosQNmPipeSemState]].


==Return Code==
==Return Code==
rc (USHORT) - return
;rc (USHORT) - return:Return code descriptions are:
Return code descriptions are:
* 0 NO_ERROR
* 0         NO_ERROR  
* 6 ERROR_INVALID_HANDLE
* 6         ERROR_INVALID_HANDLE  
* 87 ERROR_INVALID_PARAMETER
* 87         ERROR_INVALID_PARAMETER  
*120 ERROR_INVALID_FUNCTION
* 120       ERROR_INVALID_FUNCTION  
*187 ERROR_SEM_NOT_FOUND
* 187       ERROR_SEM_NOT_FOUND  
*230 ERROR_BAD_PIPE
* 230       ERROR_BAD_PIPE  
*233 ERROR_PIPE_NOT_CONNECTED
* 233       ERROR_PIPE_NOT_CONNECTED


==Remarks==
==Remarks==
Line 31: Line 26:
The system semaphore indicated by SemHandle is attached to the named pipe indicated by Handle. Up to two semaphores may be attached to a pipe, one for the serving side and one for the client side. If a semaphore is already attached to a side of the pipe, the semaphore is overridden.
The system semaphore indicated by SemHandle is attached to the named pipe indicated by Handle. Up to two semaphores may be attached to a pipe, one for the serving side and one for the client side. If a semaphore is already attached to a side of the pipe, the semaphore is overridden.


The arbitrary value assigned to KeyHandle as input for DosSetNmPipeSem is used by DosQNmPipeSemState as output. This enables the application to distinguish events specific to a particular pipe when several pipes are attached to the same semaphore. DosQNmPipeSemState can be used to provide additional information about the I/O that can be performed on the set of pipes.  
The arbitrary value assigned to KeyHandle as input for DosSetNmPipeSem is used by [[DosQNmPipeSemState]] as output. This enables the application to distinguish events specific to a particular pipe when several pipes are attached to the same semaphore. DosQNmPipeSemState can be used to provide additional information about the I/O that can be performed on the set of pipes.  


==Example Code==
==Bindings==
===C Binding===
===C===
<PRE>
<PRE>
#define INCL_DOSNMPIPES
#define INCL_DOSNMPIPES
Line 40: Line 35:
USHORT  rc = DosSetNmPipeSem(Handle, SemHandle, KeyHandle);
USHORT  rc = DosSetNmPipeSem(Handle, SemHandle, KeyHandle);


HPIPE           Handle;        /* Pipe handle */
HPIPE   Handle;        /* Pipe handle */
HSEM             SemHandle;    /* Semaphore handle */
HSEM   SemHandle;    /* Semaphore handle */
USHORT           KeyHandle;    /* Key value */
USHORT KeyHandle;    /* Key value */


USHORT           rc;            /* return code */
USHORT rc;            /* return code */
</PRE>
</PRE>


===MASM Binding===
===MASM===
<PRE>
<PRE>
EXTRN  DosSetNmPipeSem:FAR
EXTRN  DosSetNmPipeSem:FAR
Line 59: Line 54:
Returns WORD
Returns WORD
</PRE>
</PRE>
==Related Functions==
==Related Functions==
*  
* [[DosQNmPipeSemState]]


[[Category:Dos]]
[[Category:Dos]]

Revision as of 14:21, 24 May 2019

This call attaches a system semaphore to a local named pipe.

Syntax

DosSetNmPipeSem (Handle, SemHandle, KeyHandle)

Parameters

Handle (HPIPE) - input
Handle of the named pipe returned by DosMakeNmPipe or DosOpen.
SemHandle (HSEM) - input
A system semaphore handle that is cleared when the pipe (identified by Handle) has read data or write space available.
KeyHandle (USHORT) - input
An arbitrary value that is used to associate named pipe actions with result codes in DosQNmPipeSemState.

Return Code

rc (USHORT) - return
Return code descriptions are:
  • 0 NO_ERROR
  • 6 ERROR_INVALID_HANDLE
  • 87 ERROR_INVALID_PARAMETER
  • 120 ERROR_INVALID_FUNCTION
  • 187 ERROR_SEM_NOT_FOUND
  • 230 ERROR_BAD_PIPE
  • 233 ERROR_PIPE_NOT_CONNECTED

Remarks

This call is intended for use only with local named pipes. If an attempt is made to attach a semaphore to a remote named pipe, ERROR_INVALID_FUNCTION is returned.

DosSetNmPipeSem supports serving applications that need to handle a large number of incoming pipes. By using semaphores, the application avoids such resource-consuming methods as dedicating a thread for each incoming pipe, or polling each pipe with non-blocking I/O. Instead, the application issues a DosSemWait or a DosMuxSemWait and waits for notification that I/O can be performed.

The system semaphore indicated by SemHandle is attached to the named pipe indicated by Handle. Up to two semaphores may be attached to a pipe, one for the serving side and one for the client side. If a semaphore is already attached to a side of the pipe, the semaphore is overridden.

The arbitrary value assigned to KeyHandle as input for DosSetNmPipeSem is used by DosQNmPipeSemState as output. This enables the application to distinguish events specific to a particular pipe when several pipes are attached to the same semaphore. DosQNmPipeSemState can be used to provide additional information about the I/O that can be performed on the set of pipes.

Bindings

C

#define INCL_DOSNMPIPES

USHORT  rc = DosSetNmPipeSem(Handle, SemHandle, KeyHandle);

HPIPE   Handle;        /* Pipe handle */
HSEM    SemHandle;     /* Semaphore handle */
USHORT  KeyHandle;     /* Key value */

USHORT  rc;            /* return code */

MASM

EXTRN  DosSetNmPipeSem:FAR
INCL_DOSNMPIPES     EQU 1

PUSH   WORD    Handle        ;Pipe handle
PUSH   DWORD   SemHandle     ;Semaphore handle
PUSH   WORD    KeyHandle     ;Key value
CALL   DosSetNmPipeSem

Returns WORD

Related Functions