fd_set fix for PLACES

svn: r16301
This commit is contained in:
Kevin Tew 2009-10-12 21:37:53 +00:00
parent ab894fbe18
commit 6a9deb3a85
6 changed files with 55 additions and 25 deletions

View File

@ -442,6 +442,7 @@ static Scheme_Env *place_instance_init_post_kernel() {
scheme_init_stx_places(); scheme_init_stx_places();
scheme_init_sema_places(); scheme_init_sema_places();
scheme_init_gmp_places(); scheme_init_gmp_places();
scheme_alloc_global_fdset();
env = scheme_make_empty_env(); env = scheme_make_empty_env();
scheme_set_param(scheme_current_config(), MZCONFIG_ENV, (Scheme_Object *)env); scheme_set_param(scheme_current_config(), MZCONFIG_ENV, (Scheme_Object *)env);

View File

@ -59,7 +59,6 @@ static int mzerrno = 0;
#else #else
# include <errno.h> # include <errno.h>
#endif #endif
#include "schfd.h"
#ifdef USE_UNIX_SOCKETS_TCP #ifdef USE_UNIX_SOCKETS_TCP
# include <netinet/in.h> # include <netinet/in.h>
@ -93,6 +92,8 @@ struct SOCKADDR_IN {
extern int scheme_stupid_windows_machine; extern int scheme_stupid_windows_machine;
#endif #endif
#include "schfd.h"
#define TCP_BUFFER_SIZE 4096 #define TCP_BUFFER_SIZE 4096
#ifdef USE_UNIX_SOCKETS_TCP #ifdef USE_UNIX_SOCKETS_TCP
@ -157,13 +158,19 @@ typedef struct Scheme_UDP {
#if defined(WINDOWS_PROCESSES) || defined(WINDOWS_FILE_HANDLES) #if defined(WINDOWS_PROCESSES) || defined(WINDOWS_FILE_HANDLES)
# define DECL_OS_FDSET(n) fd_set n[1] # define DECL_OS_FDSET(n) fd_set n[1]
# define INIT_DECL_OS_FDSET(n) /* empty */ # define INIT_DECL_OS_FDSET(r, w, e) /* empty */
# define INIT_DECL_OS_RD_FDSET(r) /* empty */
# define INIT_DECL_OS_WR_FDSET(r) /* empty */
# define INIT_DECL_OS_ER_FDSET(r) /* empty */
# define MZ_OS_FD_ZERO(p) FD_ZERO(p) # define MZ_OS_FD_ZERO(p) FD_ZERO(p)
# define MZ_OS_FD_SET(n, p) FD_SET(n, p) # define MZ_OS_FD_SET(n, p) FD_SET(n, p)
# define MZ_OS_FD_CLR(n, p) FD_CLR(n, p) # define MZ_OS_FD_CLR(n, p) FD_CLR(n, p)
#else #else
# define DECL_OS_FDSET(n) DECL_FDSET(n, 1) # define DECL_OS_FDSET(n) DECL_FDSET(n, 1)
# define INIT_DECL_OS_FDSET(n) INIT_DECL_FDSET(n, 1) # define INIT_DECL_OS_FDSET(r, w, e) INIT_DECL_FDSET(r, w, e)
# define INIT_DECL_OS_RD_FDSET(r) INIT_DECL_RD_FDSET(r)
# define INIT_DECL_OS_WR_FDSET(r) INIT_DECL_WR_FDSET(r)
# define INIT_DECL_OS_ER_FDSET(r) INIT_DECL_ER_FDSET(r)
# define MZ_OS_FD_ZERO(p) MZ_FD_ZERO(p) # define MZ_OS_FD_ZERO(p) MZ_FD_ZERO(p)
# define MZ_OS_FD_SET(n, p) MZ_FD_SET(n, p) # define MZ_OS_FD_SET(n, p) MZ_FD_SET(n, p)
# define MZ_OS_FD_CLR(n, p) MZ_FD_CLR(n, p) # define MZ_OS_FD_CLR(n, p) MZ_FD_CLR(n, p)
@ -816,8 +823,8 @@ static int tcp_check_accept(Scheme_Object *_listener)
struct timeval time = {0, 0}; struct timeval time = {0, 0};
int sr, i; int sr, i;
INIT_DECL_OS_FDSET(readfds); INIT_DECL_OS_RD_FDSET(readfds);
INIT_DECL_OS_FDSET(exnfds); INIT_DECL_OS_ER_FDSET(exnfds);
if (LISTENER_WAS_CLOSED(listener)) if (LISTENER_WAS_CLOSED(listener))
return 1; return 1;
@ -880,8 +887,8 @@ static int tcp_check_connect(Scheme_Object *connector_p)
struct timeval time = {0, 0}; struct timeval time = {0, 0};
int sr; int sr;
INIT_DECL_OS_FDSET(writefds); INIT_DECL_OS_WR_FDSET(writefds);
INIT_DECL_OS_FDSET(exnfds); INIT_DECL_OS_ER_FDSET(exnfds);
s = *(tcp_t *)connector_p; s = *(tcp_t *)connector_p;
@ -935,8 +942,8 @@ static int tcp_check_write(Scheme_Object *port)
struct timeval time = {0, 0}; struct timeval time = {0, 0};
int sr; int sr;
INIT_DECL_OS_FDSET(writefds); INIT_DECL_OS_WR_FDSET(writefds);
INIT_DECL_OS_FDSET(exnfds); INIT_DECL_OS_ER_FDSET(exnfds);
s = data->tcp; s = data->tcp;
@ -1034,8 +1041,8 @@ static int tcp_byte_ready (Scheme_Input_Port *port)
DECL_OS_FDSET(exfds); DECL_OS_FDSET(exfds);
struct timeval time = {0, 0}; struct timeval time = {0, 0};
INIT_DECL_OS_FDSET(readfds); INIT_DECL_OS_RD_FDSET(readfds);
INIT_DECL_OS_FDSET(exfds); INIT_DECL_OS_ER_FDSET(exfds);
#endif #endif
if (port->closed) if (port->closed)
@ -2807,8 +2814,8 @@ static int udp_check_send(Scheme_Object *_udp)
struct timeval time = {0, 0}; struct timeval time = {0, 0};
int sr; int sr;
INIT_DECL_OS_FDSET(writefds); INIT_DECL_OS_WR_FDSET(writefds);
INIT_DECL_OS_FDSET(exnfds); INIT_DECL_OS_ER_FDSET(exnfds);
MZ_OS_FD_ZERO(writefds); MZ_OS_FD_ZERO(writefds);
MZ_OS_FD_SET(udp->s, writefds); MZ_OS_FD_SET(udp->s, writefds);
@ -3039,8 +3046,8 @@ static int udp_check_recv(Scheme_Object *_udp)
struct timeval time = {0, 0}; struct timeval time = {0, 0};
int sr; int sr;
INIT_DECL_OS_FDSET(readfds); INIT_DECL_OS_RD_FDSET(readfds);
INIT_DECL_OS_FDSET(exnfds); INIT_DECL_OS_ER_FDSET(exnfds);
MZ_OS_FD_ZERO(readfds); MZ_OS_FD_ZERO(readfds);
MZ_OS_FD_SET(udp->s, readfds); MZ_OS_FD_SET(udp->s, readfds);

View File

@ -77,7 +77,6 @@ static int mzerrno = 0;
extern int osk_not_console; /* set by cmd-line flag */ extern int osk_not_console; /* set by cmd-line flag */
#endif #endif
#include <math.h> /* for fmod , used by default_sleep */ #include <math.h> /* for fmod , used by default_sleep */
#include "schfd.h"
#ifndef MZ_BINARY #ifndef MZ_BINARY
# define MZ_BINARY 0 # define MZ_BINARY 0
@ -115,6 +114,8 @@ static void init_thread_memory();
# define OS_THREAD_TYPE HANDLE # define OS_THREAD_TYPE HANDLE
#endif #endif
#include "schfd.h"
#ifdef WINDOWS_FILE_HANDLES #ifdef WINDOWS_FILE_HANDLES
# define MZ_FDS # define MZ_FDS
@ -306,6 +307,8 @@ THREAD_LOCAL Scheme_Object *scheme_orig_stdout_port;
THREAD_LOCAL Scheme_Object *scheme_orig_stderr_port; THREAD_LOCAL Scheme_Object *scheme_orig_stderr_port;
THREAD_LOCAL Scheme_Object *scheme_orig_stdin_port; THREAD_LOCAL Scheme_Object *scheme_orig_stdin_port;
THREAD_LOCAL fd_set *scheme_fd_set;
Scheme_Object *(*scheme_make_stdin)(void) = NULL; Scheme_Object *(*scheme_make_stdin)(void) = NULL;
Scheme_Object *(*scheme_make_stdout)(void) = NULL; Scheme_Object *(*scheme_make_stdout)(void) = NULL;
Scheme_Object *(*scheme_make_stderr)(void) = NULL; Scheme_Object *(*scheme_make_stderr)(void) = NULL;
@ -677,6 +680,13 @@ Scheme_Object * scheme_make_eof (void)
Also implement special hooks for Windows "descriptors", like Also implement special hooks for Windows "descriptors", like
even queues and semaphores. */ even queues and semaphores. */
void scheme_alloc_global_fdset() {
#ifdef USE_FAR_MZ_FDCALLS
REGISTER_SO(scheme_fd_set);
scheme_fd_set = scheme_alloc_fdset_array(3, 0);
#endif
}
#ifdef USE_DYNAMIC_FDSET_SIZE #ifdef USE_DYNAMIC_FDSET_SIZE
static int dynamic_fd_size; static int dynamic_fd_size;
@ -4925,8 +4935,8 @@ fd_byte_ready (Scheme_Input_Port *port)
DECL_FDSET(exnfds, 1); DECL_FDSET(exnfds, 1);
struct timeval time = {0, 0}; struct timeval time = {0, 0};
INIT_DECL_FDSET(readfds, 1); INIT_DECL_RD_FDSET(readfds);
INIT_DECL_FDSET(exnfds, 1); INIT_DECL_ER_FDSET(exnfds);
MZ_FD_ZERO(readfds); MZ_FD_ZERO(readfds);
MZ_FD_ZERO(exnfds); MZ_FD_ZERO(exnfds);
@ -5938,8 +5948,8 @@ fd_write_ready (Scheme_Object *port)
struct timeval time = {0, 0}; struct timeval time = {0, 0};
int sr; int sr;
INIT_DECL_FDSET(writefds, 1); INIT_DECL_WR_FDSET(writefds);
INIT_DECL_FDSET(exnfds, 1); INIT_DECL_ER_FDSET(exnfds);
MZ_FD_ZERO(writefds); MZ_FD_ZERO(writefds);
MZ_FD_ZERO(exnfds); MZ_FD_ZERO(exnfds);
@ -8147,7 +8157,7 @@ static void default_sleep(float v, void *fds)
if (external_event_fd) { if (external_event_fd) {
DECL_FDSET(readfds, 1); DECL_FDSET(readfds, 1);
INIT_DECL_FDSET(readfds, 1); INIT_DECL_RD_FDSET(readfds);
MZ_FD_ZERO(readfds); MZ_FD_ZERO(readfds);
MZ_FD_SET(external_event_fd, readfds); MZ_FD_SET(external_event_fd, readfds);

View File

@ -1,8 +1,19 @@
#ifdef USE_FAR_MZ_FDCALLS #ifdef USE_FAR_MZ_FDCALLS
# define DECL_FDSET(n, c) static fd_set *n extern THREAD_LOCAL fd_set *scheme_fd_set;
# define INIT_DECL_FDSET(n, c) (n = (n ? (fd_set *)scheme_init_fdset_array(n, c) : (fd_set *)scheme_alloc_fdset_array(c, 1))) # define DECL_FDSET(n, c) fd_set *n
# define INIT_DECL_FDSET(r, w, e) { \
r = MZ_GET_FDSET(scheme_fd_set, 0 ); \
w = MZ_GET_FDSET(scheme_fd_set, 1 ); \
e = MZ_GET_FDSET(scheme_fd_set, 2 ); \
}
# define INIT_DECL_RD_FDSET(r) r = MZ_GET_FDSET(scheme_fd_set, 0 )
# define INIT_DECL_WR_FDSET(r) r = MZ_GET_FDSET(scheme_fd_set, 1 )
# define INIT_DECL_ER_FDSET(r) r = MZ_GET_FDSET(scheme_fd_set, 2 )
#else #else
# define DECL_FDSET(n, c) fd_set n[c] # define DECL_FDSET(n, c) fd_set n[c]
# define INIT_DECL_FDSET(n, c) /* empty */ # define INIT_DECL_FDSET(r, w, e) /* empty */
# define INIT_DECL_RD_FDSET(r) /* empty */
# define INIT_DECL_WR_FDSET(r) /* empty */
# define INIT_DECL_ER_FDSET(r) /* empty */
#endif #endif

View File

@ -3119,6 +3119,7 @@ int scheme_is_user_port(Scheme_Object *port);
int scheme_byte_ready_or_user_port_ready(Scheme_Object *p, Scheme_Schedule_Info *sinfo); int scheme_byte_ready_or_user_port_ready(Scheme_Object *p, Scheme_Schedule_Info *sinfo);
int scheme_pipe_char_count(Scheme_Object *p); int scheme_pipe_char_count(Scheme_Object *p);
void scheme_alloc_global_fdset();
#define CURRENT_INPUT_PORT(config) scheme_get_param(config, MZCONFIG_INPUT_PORT) #define CURRENT_INPUT_PORT(config) scheme_get_param(config, MZCONFIG_INPUT_PORT)
#define CURRENT_OUTPUT_PORT(config) scheme_get_param(config, MZCONFIG_OUTPUT_PORT) #define CURRENT_OUTPUT_PORT(config) scheme_get_param(config, MZCONFIG_OUTPUT_PORT)

View File

@ -3531,7 +3531,7 @@ static int check_sleep(int need_activity, int sleep_now)
scheme_notify_multithread(0); scheme_notify_multithread(0);
#if defined(USING_FDS) #if defined(USING_FDS)
INIT_DECL_FDSET(set, 3); INIT_DECL_FDSET(set, set1, set2);
set1 = (fd_set *) MZ_GET_FDSET(set, 1); set1 = (fd_set *) MZ_GET_FDSET(set, 1);
set2 = (fd_set *) MZ_GET_FDSET(set, 2); set2 = (fd_set *) MZ_GET_FDSET(set, 2);