add io_block
This commit is contained in:
parent
6e7198e23a
commit
d468ea9eb7
2
io.h
2
io.h
@ -77,6 +77,8 @@ void* io_getcookie(int64 d);
|
|||||||
|
|
||||||
/* put descriptor in non-blocking mode */
|
/* put descriptor in non-blocking mode */
|
||||||
void io_nonblock(int64 d);
|
void io_nonblock(int64 d);
|
||||||
|
/* put descriptor in blocking mode */
|
||||||
|
void io_block(int64 d);
|
||||||
/* put descriptor in close-on-exec mode */
|
/* put descriptor in close-on-exec mode */
|
||||||
void io_closeonexec(int64 d);
|
void io_closeonexec(int64 d);
|
||||||
|
|
||||||
|
15
io/io_block.3
Normal file
15
io/io_block.3
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
.TH io_block 3
|
||||||
|
.SH NAME
|
||||||
|
io_block \- switch to blocking I/O
|
||||||
|
.SH SYNTAX
|
||||||
|
.B #include <io.h>
|
||||||
|
|
||||||
|
void \fBio_block\fP(int64 fd);
|
||||||
|
.SH DESCRIPTION
|
||||||
|
io_block puts UNIX descriptor fd into ``blocking mode.''
|
||||||
|
|
||||||
|
File descriptors are normally in blocking mode, except if they come from
|
||||||
|
accept() or io_accept() and the listening socket was in non-blocking
|
||||||
|
mode.
|
||||||
|
.SH "SEE ALSO"
|
||||||
|
io_nonblock(3)
|
25
io/io_block.c
Normal file
25
io/io_block.c
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
#include <unistd.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include "io_internal.h"
|
||||||
|
|
||||||
|
#ifdef __MINGW32__
|
||||||
|
#include <winsock2.h>
|
||||||
|
#include "windoze.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef O_NDELAY
|
||||||
|
#define O_NDELAY O_NONBLOCK
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void io_block(int64 d) {
|
||||||
|
io_entry* e=array_get(&io_fds,sizeof(io_entry),d);
|
||||||
|
#ifdef __MINGW32__
|
||||||
|
unsigned long i=0;
|
||||||
|
if (ioctlsocket( d, FIONBIO, &i)==0)
|
||||||
|
if (e) e->nonblock=0;
|
||||||
|
#else
|
||||||
|
if (fcntl(d,F_SETFL,fcntl(d,F_GETFL,0) & ~O_NDELAY)==0)
|
||||||
|
if (e) e->nonblock=0;
|
||||||
|
#endif
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user