Browse Source

add io_block

master
Felix von Leitner 14 years ago
parent
commit
3c80bd9309
3 changed files with 42 additions and 0 deletions
  1. +2
    -0
      io.h
  2. +15
    -0
      io/io_block.3
  3. +25
    -0
      io/io_block.c

+ 2
- 0
io.h View File

@@ -77,6 +77,8 @@ void* io_getcookie(int64 d);

/* put descriptor in non-blocking mode */
void io_nonblock(int64 d);
/* put descriptor in blocking mode */
void io_block(int64 d);
/* put descriptor in close-on-exec mode */
void io_closeonexec(int64 d);



+ 15
- 0
io/io_block.3 View 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
- 0
io/io_block.c View 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…
Cancel
Save