[Spread-users] Spread mods
Mark Wardell
mark at netcontrol.co.za
Fri Aug 30 02:55:52 EDT 2002
Hi All,
I have done some work on the Spread module and Perl module. Maybe this
can be of some use as I wanted some timeout based poll/receive. I know
that the Perl module offers a timeout on the sp_receive but this causes
problems on Win32 with differing select/fd_set implementations.
I have tested in my environment (Win2k) and it seems to work fine. Let
me know if this can be of some use to someone or if there are any
problems.
Cheers
Mark
sp.c
----
int SP_poll( mailbox mbox, double timeout )
{
int num_bytes;
int ses;
int ret;
fd_set readfds;
Mutex_lock( &Struct_mutex );
/* verify mbox */
ses = SP_get_session( mbox );
Mutex_unlock( &Struct_mutex );
if( ses < 0 ) return( ILLEGAL_SESSION );
if (timeout) {
struct timeval towait;
towait.tv_sec = 0L;
towait.tv_usec = 0L;
towait.tv_sec = (unsigned long)timeout;
towait.tv_usec = (unsigned
long)(1000000.0*(timeout-(double)towait.tv_sec));
FD_ZERO(&readfds);
FD_SET(mbox, &readfds);
ret = select(mbox+1, &readfds, NULL, NULL, &towait);
if( !ret ) sock_set_errno( ERR_TIMEDOUT );
if( ret < 1 ) return( sock_errno );
}
ret = ioctl( mbox, FIONREAD, &num_bytes);
if( ret < 0 ) return( ILLEGAL_SESSION );
return( num_bytes );
}
sp_func.h
---------
int SP_poll( mailbox mbox, double timeout );
spread.xs
---------
SV *
GC_poll(svmbox, svtimeout=&PL_sv_undef)
SV * svmbox
SV * svtimeout
PREINIT:
int mbox = SvIV(svmbox);
double timeout;
CODE:
timeout = SvNV(svtimeout);
mbox = SP_poll(mbox,timeout);
if(mbox<0) {
SetSpErrorNo(mbox);
RETVAL = &PL_sv_undef;
} else {
RETVAL = newSViv(mbox);
}
OUTPUT:
RETVAL
More information about the Spread-users
mailing list