Named pipe in winows, difference between FILE_FLAG_OVERLAPPED and PIPE_NOWAIT
up vote
1
down vote
favorite
I am using named pipe in windows and confused about the difference between FILE_FLAG_OVERLAPPED
and PIPE_NOWAIT
which are parameters set in CreateNamedPipe
,I set parameters like this.
HANDLE hPipe = CreateNamedPipe(
lpszPipename, // pipe name
PIPE_ACCESS_DUPLEX | // read/write access
FILE_FLAG_OVERLAPPED, // overlapped mode
PIPE_TYPE_MESSAGE | // message-type pipe
PIPE_READMODE_MESSAGE | // message read mode
PIPE_WAIT, // blocking mode
PIPE_UNLIMITED_INSTANCES, // unlimited instances
BUFSIZE * sizeof(TCHAR), // output buffer size
BUFSIZE * sizeof(TCHAR), // input buffer size
PIPE_TIMEOUT, // client time-out
NULL); // default security attributes
the ConnectNamedPipe
return immediately and I get ERROR_IO_PENDING
from GetLastError
.With a nonblocking-wait handle, the connect operation returns zero immediately, and the GetLastError function returns ERROR_IO_PENDING
.However the MSDN tells:
With a nonblocking-wait handle, the connect operation returns zero immediately, and the GetLastError function returns ERROR_PIPE_LISTENING.
so, what does nonblocking-wait
mean, PIPE_NOWAIT
or FILE_FLAG_OVERLAPPED
, thanks a lot!
winapi ipc named-pipes overlap
add a comment |
up vote
1
down vote
favorite
I am using named pipe in windows and confused about the difference between FILE_FLAG_OVERLAPPED
and PIPE_NOWAIT
which are parameters set in CreateNamedPipe
,I set parameters like this.
HANDLE hPipe = CreateNamedPipe(
lpszPipename, // pipe name
PIPE_ACCESS_DUPLEX | // read/write access
FILE_FLAG_OVERLAPPED, // overlapped mode
PIPE_TYPE_MESSAGE | // message-type pipe
PIPE_READMODE_MESSAGE | // message read mode
PIPE_WAIT, // blocking mode
PIPE_UNLIMITED_INSTANCES, // unlimited instances
BUFSIZE * sizeof(TCHAR), // output buffer size
BUFSIZE * sizeof(TCHAR), // input buffer size
PIPE_TIMEOUT, // client time-out
NULL); // default security attributes
the ConnectNamedPipe
return immediately and I get ERROR_IO_PENDING
from GetLastError
.With a nonblocking-wait handle, the connect operation returns zero immediately, and the GetLastError function returns ERROR_IO_PENDING
.However the MSDN tells:
With a nonblocking-wait handle, the connect operation returns zero immediately, and the GetLastError function returns ERROR_PIPE_LISTENING.
so, what does nonblocking-wait
mean, PIPE_NOWAIT
or FILE_FLAG_OVERLAPPED
, thanks a lot!
winapi ipc named-pipes overlap
It seems the MSDN uses the term "nonblocking mode" when usingPIPE_ NOWAIT
, and the term "overlapped mode" when usingFILE_FLAG_OVERLAPPED
.PIPE_NOWAIT
is "supported for compatibility with Microsoft LAN Manager version 2.0 and should not be used to achieve asynchronous I/O".
– IInspectable
2 days ago
Very different options. FILE_FLAG_OVERLAPPED sets up the socket so it can handle asynchronous I/O, you can call ReadFile() with an OVERLAPPED argument and handle the read completion later. Very common for pipes, unless the traffic rate is very high you want to avoid blocking a thread too much. PIPE_NOWAIT is useful for synchronous I/O, it prevents ReadFile() from blocking if there is no data yet. Repeatedly calling ReadFile() is then required, polling in common terms. Look at a library like boost::asio to take care of the plumbing.
– Hans Passant
2 days ago
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I am using named pipe in windows and confused about the difference between FILE_FLAG_OVERLAPPED
and PIPE_NOWAIT
which are parameters set in CreateNamedPipe
,I set parameters like this.
HANDLE hPipe = CreateNamedPipe(
lpszPipename, // pipe name
PIPE_ACCESS_DUPLEX | // read/write access
FILE_FLAG_OVERLAPPED, // overlapped mode
PIPE_TYPE_MESSAGE | // message-type pipe
PIPE_READMODE_MESSAGE | // message read mode
PIPE_WAIT, // blocking mode
PIPE_UNLIMITED_INSTANCES, // unlimited instances
BUFSIZE * sizeof(TCHAR), // output buffer size
BUFSIZE * sizeof(TCHAR), // input buffer size
PIPE_TIMEOUT, // client time-out
NULL); // default security attributes
the ConnectNamedPipe
return immediately and I get ERROR_IO_PENDING
from GetLastError
.With a nonblocking-wait handle, the connect operation returns zero immediately, and the GetLastError function returns ERROR_IO_PENDING
.However the MSDN tells:
With a nonblocking-wait handle, the connect operation returns zero immediately, and the GetLastError function returns ERROR_PIPE_LISTENING.
so, what does nonblocking-wait
mean, PIPE_NOWAIT
or FILE_FLAG_OVERLAPPED
, thanks a lot!
winapi ipc named-pipes overlap
I am using named pipe in windows and confused about the difference between FILE_FLAG_OVERLAPPED
and PIPE_NOWAIT
which are parameters set in CreateNamedPipe
,I set parameters like this.
HANDLE hPipe = CreateNamedPipe(
lpszPipename, // pipe name
PIPE_ACCESS_DUPLEX | // read/write access
FILE_FLAG_OVERLAPPED, // overlapped mode
PIPE_TYPE_MESSAGE | // message-type pipe
PIPE_READMODE_MESSAGE | // message read mode
PIPE_WAIT, // blocking mode
PIPE_UNLIMITED_INSTANCES, // unlimited instances
BUFSIZE * sizeof(TCHAR), // output buffer size
BUFSIZE * sizeof(TCHAR), // input buffer size
PIPE_TIMEOUT, // client time-out
NULL); // default security attributes
the ConnectNamedPipe
return immediately and I get ERROR_IO_PENDING
from GetLastError
.With a nonblocking-wait handle, the connect operation returns zero immediately, and the GetLastError function returns ERROR_IO_PENDING
.However the MSDN tells:
With a nonblocking-wait handle, the connect operation returns zero immediately, and the GetLastError function returns ERROR_PIPE_LISTENING.
so, what does nonblocking-wait
mean, PIPE_NOWAIT
or FILE_FLAG_OVERLAPPED
, thanks a lot!
winapi ipc named-pipes overlap
winapi ipc named-pipes overlap
edited 2 days ago
πάντα ῥεῖ
71.1k970132
71.1k970132
asked 2 days ago
Gordon
544
544
It seems the MSDN uses the term "nonblocking mode" when usingPIPE_ NOWAIT
, and the term "overlapped mode" when usingFILE_FLAG_OVERLAPPED
.PIPE_NOWAIT
is "supported for compatibility with Microsoft LAN Manager version 2.0 and should not be used to achieve asynchronous I/O".
– IInspectable
2 days ago
Very different options. FILE_FLAG_OVERLAPPED sets up the socket so it can handle asynchronous I/O, you can call ReadFile() with an OVERLAPPED argument and handle the read completion later. Very common for pipes, unless the traffic rate is very high you want to avoid blocking a thread too much. PIPE_NOWAIT is useful for synchronous I/O, it prevents ReadFile() from blocking if there is no data yet. Repeatedly calling ReadFile() is then required, polling in common terms. Look at a library like boost::asio to take care of the plumbing.
– Hans Passant
2 days ago
add a comment |
It seems the MSDN uses the term "nonblocking mode" when usingPIPE_ NOWAIT
, and the term "overlapped mode" when usingFILE_FLAG_OVERLAPPED
.PIPE_NOWAIT
is "supported for compatibility with Microsoft LAN Manager version 2.0 and should not be used to achieve asynchronous I/O".
– IInspectable
2 days ago
Very different options. FILE_FLAG_OVERLAPPED sets up the socket so it can handle asynchronous I/O, you can call ReadFile() with an OVERLAPPED argument and handle the read completion later. Very common for pipes, unless the traffic rate is very high you want to avoid blocking a thread too much. PIPE_NOWAIT is useful for synchronous I/O, it prevents ReadFile() from blocking if there is no data yet. Repeatedly calling ReadFile() is then required, polling in common terms. Look at a library like boost::asio to take care of the plumbing.
– Hans Passant
2 days ago
It seems the MSDN uses the term "nonblocking mode" when using
PIPE_ NOWAIT
, and the term "overlapped mode" when using FILE_FLAG_OVERLAPPED
. PIPE_NOWAIT
is "supported for compatibility with Microsoft LAN Manager version 2.0 and should not be used to achieve asynchronous I/O".– IInspectable
2 days ago
It seems the MSDN uses the term "nonblocking mode" when using
PIPE_ NOWAIT
, and the term "overlapped mode" when using FILE_FLAG_OVERLAPPED
. PIPE_NOWAIT
is "supported for compatibility with Microsoft LAN Manager version 2.0 and should not be used to achieve asynchronous I/O".– IInspectable
2 days ago
Very different options. FILE_FLAG_OVERLAPPED sets up the socket so it can handle asynchronous I/O, you can call ReadFile() with an OVERLAPPED argument and handle the read completion later. Very common for pipes, unless the traffic rate is very high you want to avoid blocking a thread too much. PIPE_NOWAIT is useful for synchronous I/O, it prevents ReadFile() from blocking if there is no data yet. Repeatedly calling ReadFile() is then required, polling in common terms. Look at a library like boost::asio to take care of the plumbing.
– Hans Passant
2 days ago
Very different options. FILE_FLAG_OVERLAPPED sets up the socket so it can handle asynchronous I/O, you can call ReadFile() with an OVERLAPPED argument and handle the read completion later. Very common for pipes, unless the traffic rate is very high you want to avoid blocking a thread too much. PIPE_NOWAIT is useful for synchronous I/O, it prevents ReadFile() from blocking if there is no data yet. Repeatedly calling ReadFile() is then required, polling in common terms. Look at a library like boost::asio to take care of the plumbing.
– Hans Passant
2 days ago
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
PIPE_NOWAIT
mean that Nonblocking mode is enabled on handle. In this mode, ReadFile
, WriteFile
, and ConnectNamedPipe
always completed immediately.
the FILE_FLAG_OVERLAPPED
mean asynchronous mode is enabled on handle. If this mode is enabled, all not synchronous io [1] operations always return immediately.
so FILE_FLAG_OVERLAPPED
vs PIPE_NOWAIT
- this is return immediately vs completed immediately.
completed immediately (which include return immediately ) mean that io operation is already completed when api return. but visa versa not true. if operation return immediately this not mean that operation is completed already. if operation still not completed ntapi return code STATUS_PENDING
. win32 api in such situations usual set last error to ERROR_IO_PENDING
.
exist 3 way determinate when io operation completed in case asynchronous handle mode.
- bind handle to IOCP (via
CreateIoCompletionPort
orBindIoCompletionCallback
orCreateThreadpoolIo
). as result when
io complete - pointer toOVERLAPPED
which we pass to io call -
will be queued back to IOCP (in caseBindIoCompletionCallback
orCreateThreadpoolIo
system yourself create IOCP and listen on it
and call our registered callback, when pointer toOVERLAPPED
will
be queued to IOCP) - some win32 api such
ReadFileEx
orWriteFileEx
and all ntapi let
specify APC completion routine which will be called in context of
thread, which begin io operation, when io operation is completed.
thread must do alertable wait in this case. this wait is not
compatible with bind handle to IOCP (we can not use APC routine in
api call if file handle binded to IOCP - system return invalid
parameter error) - we can create event and pass it to api call (via
OVERLAPPED::hEvent
) - in this case this event will be reset by
system when io operation begin and set to signaled state when io
operation is completed. unlike first 2 option in this case we have
no additional context (in face pointer toOVERLAPPED
) when io
operation is completed. usually this is worst option.
[1] exist some io operations which is always synchronous api. for example GetFileInformationByHandleEx
, SetFileInformationByHandle
. but almost io operations is not synchronous io. all this io operations take pointer to OVERLAPPED
as parameter. so if no pointer to OVERLAPPED
in api signature - this is synchronous api call. if exist - usually asynchronous (exception CancelIoEx
for example where pointer to overlapped is related not to current operation but to previous io operation which we want cancel). in particular ReadFile
, WriteFile
, DeviceIoControl
, ConnectNamedPipe
( internally this is call DeviceIoControl
with FSCTL_PIPE_LISTEN
) ) is not synchronous io api
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
PIPE_NOWAIT
mean that Nonblocking mode is enabled on handle. In this mode, ReadFile
, WriteFile
, and ConnectNamedPipe
always completed immediately.
the FILE_FLAG_OVERLAPPED
mean asynchronous mode is enabled on handle. If this mode is enabled, all not synchronous io [1] operations always return immediately.
so FILE_FLAG_OVERLAPPED
vs PIPE_NOWAIT
- this is return immediately vs completed immediately.
completed immediately (which include return immediately ) mean that io operation is already completed when api return. but visa versa not true. if operation return immediately this not mean that operation is completed already. if operation still not completed ntapi return code STATUS_PENDING
. win32 api in such situations usual set last error to ERROR_IO_PENDING
.
exist 3 way determinate when io operation completed in case asynchronous handle mode.
- bind handle to IOCP (via
CreateIoCompletionPort
orBindIoCompletionCallback
orCreateThreadpoolIo
). as result when
io complete - pointer toOVERLAPPED
which we pass to io call -
will be queued back to IOCP (in caseBindIoCompletionCallback
orCreateThreadpoolIo
system yourself create IOCP and listen on it
and call our registered callback, when pointer toOVERLAPPED
will
be queued to IOCP) - some win32 api such
ReadFileEx
orWriteFileEx
and all ntapi let
specify APC completion routine which will be called in context of
thread, which begin io operation, when io operation is completed.
thread must do alertable wait in this case. this wait is not
compatible with bind handle to IOCP (we can not use APC routine in
api call if file handle binded to IOCP - system return invalid
parameter error) - we can create event and pass it to api call (via
OVERLAPPED::hEvent
) - in this case this event will be reset by
system when io operation begin and set to signaled state when io
operation is completed. unlike first 2 option in this case we have
no additional context (in face pointer toOVERLAPPED
) when io
operation is completed. usually this is worst option.
[1] exist some io operations which is always synchronous api. for example GetFileInformationByHandleEx
, SetFileInformationByHandle
. but almost io operations is not synchronous io. all this io operations take pointer to OVERLAPPED
as parameter. so if no pointer to OVERLAPPED
in api signature - this is synchronous api call. if exist - usually asynchronous (exception CancelIoEx
for example where pointer to overlapped is related not to current operation but to previous io operation which we want cancel). in particular ReadFile
, WriteFile
, DeviceIoControl
, ConnectNamedPipe
( internally this is call DeviceIoControl
with FSCTL_PIPE_LISTEN
) ) is not synchronous io api
add a comment |
up vote
1
down vote
PIPE_NOWAIT
mean that Nonblocking mode is enabled on handle. In this mode, ReadFile
, WriteFile
, and ConnectNamedPipe
always completed immediately.
the FILE_FLAG_OVERLAPPED
mean asynchronous mode is enabled on handle. If this mode is enabled, all not synchronous io [1] operations always return immediately.
so FILE_FLAG_OVERLAPPED
vs PIPE_NOWAIT
- this is return immediately vs completed immediately.
completed immediately (which include return immediately ) mean that io operation is already completed when api return. but visa versa not true. if operation return immediately this not mean that operation is completed already. if operation still not completed ntapi return code STATUS_PENDING
. win32 api in such situations usual set last error to ERROR_IO_PENDING
.
exist 3 way determinate when io operation completed in case asynchronous handle mode.
- bind handle to IOCP (via
CreateIoCompletionPort
orBindIoCompletionCallback
orCreateThreadpoolIo
). as result when
io complete - pointer toOVERLAPPED
which we pass to io call -
will be queued back to IOCP (in caseBindIoCompletionCallback
orCreateThreadpoolIo
system yourself create IOCP and listen on it
and call our registered callback, when pointer toOVERLAPPED
will
be queued to IOCP) - some win32 api such
ReadFileEx
orWriteFileEx
and all ntapi let
specify APC completion routine which will be called in context of
thread, which begin io operation, when io operation is completed.
thread must do alertable wait in this case. this wait is not
compatible with bind handle to IOCP (we can not use APC routine in
api call if file handle binded to IOCP - system return invalid
parameter error) - we can create event and pass it to api call (via
OVERLAPPED::hEvent
) - in this case this event will be reset by
system when io operation begin and set to signaled state when io
operation is completed. unlike first 2 option in this case we have
no additional context (in face pointer toOVERLAPPED
) when io
operation is completed. usually this is worst option.
[1] exist some io operations which is always synchronous api. for example GetFileInformationByHandleEx
, SetFileInformationByHandle
. but almost io operations is not synchronous io. all this io operations take pointer to OVERLAPPED
as parameter. so if no pointer to OVERLAPPED
in api signature - this is synchronous api call. if exist - usually asynchronous (exception CancelIoEx
for example where pointer to overlapped is related not to current operation but to previous io operation which we want cancel). in particular ReadFile
, WriteFile
, DeviceIoControl
, ConnectNamedPipe
( internally this is call DeviceIoControl
with FSCTL_PIPE_LISTEN
) ) is not synchronous io api
add a comment |
up vote
1
down vote
up vote
1
down vote
PIPE_NOWAIT
mean that Nonblocking mode is enabled on handle. In this mode, ReadFile
, WriteFile
, and ConnectNamedPipe
always completed immediately.
the FILE_FLAG_OVERLAPPED
mean asynchronous mode is enabled on handle. If this mode is enabled, all not synchronous io [1] operations always return immediately.
so FILE_FLAG_OVERLAPPED
vs PIPE_NOWAIT
- this is return immediately vs completed immediately.
completed immediately (which include return immediately ) mean that io operation is already completed when api return. but visa versa not true. if operation return immediately this not mean that operation is completed already. if operation still not completed ntapi return code STATUS_PENDING
. win32 api in such situations usual set last error to ERROR_IO_PENDING
.
exist 3 way determinate when io operation completed in case asynchronous handle mode.
- bind handle to IOCP (via
CreateIoCompletionPort
orBindIoCompletionCallback
orCreateThreadpoolIo
). as result when
io complete - pointer toOVERLAPPED
which we pass to io call -
will be queued back to IOCP (in caseBindIoCompletionCallback
orCreateThreadpoolIo
system yourself create IOCP and listen on it
and call our registered callback, when pointer toOVERLAPPED
will
be queued to IOCP) - some win32 api such
ReadFileEx
orWriteFileEx
and all ntapi let
specify APC completion routine which will be called in context of
thread, which begin io operation, when io operation is completed.
thread must do alertable wait in this case. this wait is not
compatible with bind handle to IOCP (we can not use APC routine in
api call if file handle binded to IOCP - system return invalid
parameter error) - we can create event and pass it to api call (via
OVERLAPPED::hEvent
) - in this case this event will be reset by
system when io operation begin and set to signaled state when io
operation is completed. unlike first 2 option in this case we have
no additional context (in face pointer toOVERLAPPED
) when io
operation is completed. usually this is worst option.
[1] exist some io operations which is always synchronous api. for example GetFileInformationByHandleEx
, SetFileInformationByHandle
. but almost io operations is not synchronous io. all this io operations take pointer to OVERLAPPED
as parameter. so if no pointer to OVERLAPPED
in api signature - this is synchronous api call. if exist - usually asynchronous (exception CancelIoEx
for example where pointer to overlapped is related not to current operation but to previous io operation which we want cancel). in particular ReadFile
, WriteFile
, DeviceIoControl
, ConnectNamedPipe
( internally this is call DeviceIoControl
with FSCTL_PIPE_LISTEN
) ) is not synchronous io api
PIPE_NOWAIT
mean that Nonblocking mode is enabled on handle. In this mode, ReadFile
, WriteFile
, and ConnectNamedPipe
always completed immediately.
the FILE_FLAG_OVERLAPPED
mean asynchronous mode is enabled on handle. If this mode is enabled, all not synchronous io [1] operations always return immediately.
so FILE_FLAG_OVERLAPPED
vs PIPE_NOWAIT
- this is return immediately vs completed immediately.
completed immediately (which include return immediately ) mean that io operation is already completed when api return. but visa versa not true. if operation return immediately this not mean that operation is completed already. if operation still not completed ntapi return code STATUS_PENDING
. win32 api in such situations usual set last error to ERROR_IO_PENDING
.
exist 3 way determinate when io operation completed in case asynchronous handle mode.
- bind handle to IOCP (via
CreateIoCompletionPort
orBindIoCompletionCallback
orCreateThreadpoolIo
). as result when
io complete - pointer toOVERLAPPED
which we pass to io call -
will be queued back to IOCP (in caseBindIoCompletionCallback
orCreateThreadpoolIo
system yourself create IOCP and listen on it
and call our registered callback, when pointer toOVERLAPPED
will
be queued to IOCP) - some win32 api such
ReadFileEx
orWriteFileEx
and all ntapi let
specify APC completion routine which will be called in context of
thread, which begin io operation, when io operation is completed.
thread must do alertable wait in this case. this wait is not
compatible with bind handle to IOCP (we can not use APC routine in
api call if file handle binded to IOCP - system return invalid
parameter error) - we can create event and pass it to api call (via
OVERLAPPED::hEvent
) - in this case this event will be reset by
system when io operation begin and set to signaled state when io
operation is completed. unlike first 2 option in this case we have
no additional context (in face pointer toOVERLAPPED
) when io
operation is completed. usually this is worst option.
[1] exist some io operations which is always synchronous api. for example GetFileInformationByHandleEx
, SetFileInformationByHandle
. but almost io operations is not synchronous io. all this io operations take pointer to OVERLAPPED
as parameter. so if no pointer to OVERLAPPED
in api signature - this is synchronous api call. if exist - usually asynchronous (exception CancelIoEx
for example where pointer to overlapped is related not to current operation but to previous io operation which we want cancel). in particular ReadFile
, WriteFile
, DeviceIoControl
, ConnectNamedPipe
( internally this is call DeviceIoControl
with FSCTL_PIPE_LISTEN
) ) is not synchronous io api
answered 2 days ago
RbMm
16.4k11224
16.4k11224
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53237751%2fnamed-pipe-in-winows-difference-between-file-flag-overlapped-and-pipe-nowait%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
It seems the MSDN uses the term "nonblocking mode" when using
PIPE_ NOWAIT
, and the term "overlapped mode" when usingFILE_FLAG_OVERLAPPED
.PIPE_NOWAIT
is "supported for compatibility with Microsoft LAN Manager version 2.0 and should not be used to achieve asynchronous I/O".– IInspectable
2 days ago
Very different options. FILE_FLAG_OVERLAPPED sets up the socket so it can handle asynchronous I/O, you can call ReadFile() with an OVERLAPPED argument and handle the read completion later. Very common for pipes, unless the traffic rate is very high you want to avoid blocking a thread too much. PIPE_NOWAIT is useful for synchronous I/O, it prevents ReadFile() from blocking if there is no data yet. Repeatedly calling ReadFile() is then required, polling in common terms. Look at a library like boost::asio to take care of the plumbing.
– Hans Passant
2 days ago