This commit is contained in:
Manoj Ampalam 2016-01-03 00:50:16 -08:00
parent 3c4a0b19ac
commit 533dec9304
2 changed files with 13 additions and 4 deletions

View File

@ -23,13 +23,15 @@ int fd_table_get_min_index() {
{ {
bitmap++; bitmap++;
min_index += 8; min_index += 8;
if (min_index >= MAX_FDS)
return -1;
} }
tmp = *bitmap; tmp = *bitmap;
while (tmp & 0x80) while (tmp & 0x80)
{ {
tmp << 1; tmp <<= 1;
min_index++; min_index++;
} }
@ -47,7 +49,7 @@ void fd_table_clear(int index)
{ {
fd_table.w32_ios[index]->table_index = -1; fd_table.w32_ios[index]->table_index = -1;
fd_table.w32_ios[index] = NULL; fd_table.w32_ios[index] = NULL;
FD_SET(index, &(fd_table.occupied)); FD_CLR(index, &(fd_table.occupied));
} }
void w32posix_initialize() { void w32posix_initialize() {
@ -134,6 +136,7 @@ int w32_close(int fd) {
fd_table_clear(pio->table_index); fd_table_clear(pio->table_index);
if ((pio->type == LISTEN_FD) || (pio->type == SOCK_FD)) { if ((pio->type == LISTEN_FD) || (pio->type == SOCK_FD)) {
socketio_close(pio); socketio_close(pio);
return 0;
} }
else else
return -1; return -1;

View File

@ -6,16 +6,22 @@
#include <stdio.h> #include <stdio.h>
//File Descriptor definitions //File Descriptor definitions
#if !defined(MAX_FDS)
#define MAX_FDS 128 //a 2^n number #define MAX_FDS 128 //a 2^n number
#endif
typedef struct w32_fd_set_ { typedef struct w32_fd_set_ {
unsigned char bitmap[MAX_FDS >> 3]; unsigned char bitmap[MAX_FDS >> 3];
}w32_fd_set; }w32_fd_set;
#define fd_set w32_fd_set #define fd_set w32_fd_set
#undef FD_ZERO
#define FD_ZERO(set) (memset( (set), 0, sizeof(w32_fd_set))) #define FD_ZERO(set) (memset( (set), 0, sizeof(w32_fd_set)))
#undef FD_SET
#define FD_SET(fd,set) ( (set)->bitmap[(fd) >> 3] |= (0x80 >> ((fd) % 8))) #define FD_SET(fd,set) ( (set)->bitmap[(fd) >> 3] |= (0x80 >> ((fd) % 8)))
#undef FD_ISSET
#define FD_ISSET(fd, set) (( (set)->bitmap[(fd) >> 3] & (0x80 >> ((fd) % 8)))?1:0) #define FD_ISSET(fd, set) (( (set)->bitmap[(fd) >> 3] & (0x80 >> ((fd) % 8)))?1:0)
#undef FD_CLR
#define FD_CLR(fd, set) ((set)->bitmap[(fd) >> 3] &= (~(0x80 >> ((fd) % 8)))) #define FD_CLR(fd, set) ((set)->bitmap[(fd) >> 3] &= (~(0x80 >> ((fd) % 8))))
#define STDIN_FILENO 0 #define STDIN_FILENO 0
@ -25,8 +31,8 @@ typedef struct w32_fd_set_ {
//fcntl commands //fcntl commands
#define F_GETFL 0x1 #define F_GETFL 0x1
#define F_SETFL 0x2 #define F_SETFL 0x2
#define F_GETFL 0x4 #define F_GETFD 0x4
#define F_SETFL 0x8 #define F_SETFD 0x8
//fd status flags //fd status flags
#define O_NONBLOCK 0x1 #define O_NONBLOCK 0x1