2005-01-04 21:18:08 +00:00
|
|
|
#ifndef _MUX_H_
|
|
|
|
#define _MUX_H_ 1
|
|
|
|
#if defined(__cplusplus)
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
AUTOLIB(mux)
|
|
|
|
|
2003-12-06 18:08:52 +00:00
|
|
|
typedef struct Mux Mux;
|
|
|
|
typedef struct Muxrpc Muxrpc;
|
|
|
|
typedef struct Muxqueue Muxqueue;
|
|
|
|
|
|
|
|
struct Muxrpc
|
|
|
|
{
|
2006-06-25 23:50:02 +00:00
|
|
|
Mux *mux;
|
2003-12-06 18:08:52 +00:00
|
|
|
Muxrpc *next;
|
|
|
|
Muxrpc *prev;
|
|
|
|
Rendez r;
|
|
|
|
uint tag;
|
|
|
|
void *p;
|
2006-06-25 23:50:02 +00:00
|
|
|
int waiting;
|
2006-11-04 18:46:00 +00:00
|
|
|
int async;
|
2003-12-06 18:08:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct Mux
|
|
|
|
{
|
|
|
|
uint mintag; /* to be filled by client */
|
|
|
|
uint maxtag;
|
|
|
|
int (*send)(Mux*, void*);
|
|
|
|
void *(*recv)(Mux*);
|
2006-11-04 18:46:00 +00:00
|
|
|
int (*nbrecv)(Mux*, void**);
|
2003-12-06 18:08:52 +00:00
|
|
|
int (*gettag)(Mux*, void*);
|
|
|
|
int (*settag)(Mux*, void*, uint);
|
|
|
|
void *aux; /* for private use by client */
|
|
|
|
|
|
|
|
/* private */
|
2004-01-09 00:04:55 +00:00
|
|
|
QLock lk; /* must be first for muxinit */
|
2003-12-06 18:08:52 +00:00
|
|
|
QLock inlk;
|
|
|
|
QLock outlk;
|
|
|
|
Rendez tagrend;
|
|
|
|
Rendez rpcfork;
|
|
|
|
Muxqueue *readq;
|
|
|
|
Muxqueue *writeq;
|
|
|
|
uint nwait;
|
|
|
|
uint mwait;
|
|
|
|
uint freetag;
|
|
|
|
Muxrpc **wait;
|
2006-06-25 23:50:02 +00:00
|
|
|
Muxrpc *muxer;
|
2003-12-06 18:08:52 +00:00
|
|
|
Muxrpc sleep;
|
|
|
|
};
|
|
|
|
|
|
|
|
void muxinit(Mux*);
|
|
|
|
void* muxrpc(Mux*, void*);
|
2006-06-25 23:50:02 +00:00
|
|
|
void muxprocs(Mux*);
|
|
|
|
Muxrpc* muxrpcstart(Mux*, void*);
|
2006-11-04 18:46:00 +00:00
|
|
|
int muxrpccanfinish(Muxrpc*, void**);
|
2003-12-06 18:08:52 +00:00
|
|
|
|
|
|
|
/* private */
|
|
|
|
int _muxsend(Mux*, void*);
|
2006-11-04 18:46:00 +00:00
|
|
|
int _muxrecv(Mux*, int, void**);
|
2003-12-06 18:08:52 +00:00
|
|
|
void _muxsendproc(void*);
|
|
|
|
void _muxrecvproc(void*);
|
|
|
|
Muxqueue *_muxqalloc(void);
|
|
|
|
int _muxqsend(Muxqueue*, void*);
|
|
|
|
void *_muxqrecv(Muxqueue*);
|
|
|
|
void _muxqhangup(Muxqueue*);
|
2006-11-04 18:46:00 +00:00
|
|
|
int _muxnbqrecv(Muxqueue*, void**);
|
2003-12-06 18:08:52 +00:00
|
|
|
|
2005-01-04 21:18:08 +00:00
|
|
|
#if defined(__cplusplus)
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#endif
|