extend SWI compatinbility.

This commit is contained in:
Vítor Santos Costa 2010-06-17 00:33:57 +01:00
parent 3f21f2acc2
commit fa91738193
2 changed files with 59 additions and 1 deletions

View File

@ -102,6 +102,8 @@ typedef enum
typedef struct tempfile * TempFile; /* pl-os.c */
typedef struct canonical_dir * CanonicalDir; /* pl-os.c */
typedef struct on_halt * OnHalt; /* pl-os.c */
typedef struct extension_cell * ExtensionCell; /* pl-ext.c */
typedef struct initialise_handle * InitialiseHandle;
/* The GD global variable */
typedef struct {
@ -151,6 +153,17 @@ typedef struct {
atom_t *for_code[256]; /* code --> one-char-atom */
} atoms;
struct
{ ExtensionCell _ext_head; /* head of registered extensions */
ExtensionCell _ext_tail; /* tail of this chain */
InitialiseHandle initialise_head; /* PL_initialise_hook() */
InitialiseHandle initialise_tail;
PL_dispatch_hook_t dispatch_events; /* PL_dispatch_hook() */
int _loaded; /* system extensions are loaded */
} foreign;
} gds_t;
extern gds_t gds;
@ -498,7 +511,6 @@ typedef double real;
#endif
#define PL_dispatch(FD, COM)
extern int PL_unify_char(term_t chr, int c, int how);
extern int PL_get_char(term_t chr, int *c, int eof);
extern int PL_get_text(term_t l, PL_chars_t *text, int flags);

View File

@ -608,3 +608,49 @@ warning(const char *fm, ...)
return TRUE;
}
#if defined(HAVE_SELECT) && !defined(__WINDOWS__)
#ifdef __WINDOWS__
#include <winsock2.h>
#endif
static int
input_on_fd(int fd)
{ fd_set rfds;
struct timeval tv;
FD_ZERO(&rfds);
FD_SET(fd, &rfds);
tv.tv_sec = 0;
tv.tv_usec = 0;
return select(fd+1, &rfds, NULL, NULL, &tv) != 0;
}
#else
#define input_on_fd(fd) 1
#endif
X_API int
PL_dispatch(int fd, int wait)
{ if ( wait == PL_DISPATCH_INSTALLED )
return GD->foreign.dispatch_events ? TRUE : FALSE;
if ( GD->foreign.dispatch_events && PL_thread_self() == 1 )
{ if ( wait == PL_DISPATCH_WAIT )
{ while( !input_on_fd(fd) )
{ if ( PL_handle_signals() < 0 )
return FALSE;
(*GD->foreign.dispatch_events)(fd);
}
} else
{ (*GD->foreign.dispatch_events)(fd);
if ( PL_handle_signals() < 0 )
return FALSE;
}
}
return TRUE;
}