lib9p: expose Srv.forker handler and srvforker(), threadsrvforker() and threadsrv() functions
To use srvrease()/srvaquire() we need to have a way to spawn new processes to handle the service loop. This functionality was provided by the internal _forker() function which was eigther rfork or libthread based implementation depending on if postmountsrv() or threadpostmountsrv() where called. For servers who want to use srv() directly, _forker would not be initialized so srvrelease() could not be used. To untangle this, we get rid of the global _forker handler and put the handler in the Srv structure. Which will get initialized (when nil) to eigther srvforker() or threadsrvforker() depending on if the thread or non-thread entry points where used. For symmetry, we provde new threadsrv() and threadpostsrv() functions which handle the default initialization of Srv.forker. This also allows a user to provide his own forker function, maybe to conserve stack space. To avoid dead code, we put each of these function in their own object file. Note, this also allows a user to define its own srvforker() symbol.
This commit is contained in:
parent
013b498314
commit
f6509078ed
15 changed files with 201 additions and 125 deletions
53
sys/man/2/9p
53
sys/man/2/9p
|
@ -9,16 +9,21 @@ estrdup9p,
|
|||
listensrv,
|
||||
postmountsrv,
|
||||
postsharesrv,
|
||||
postsrv,
|
||||
readbuf,
|
||||
readstr,
|
||||
respond,
|
||||
responderror,
|
||||
srv
|
||||
srvacquire,
|
||||
srvforker,
|
||||
srvrelease,
|
||||
threadlistensrv,
|
||||
threadpostmountsrv,
|
||||
threadpostsharesrv,
|
||||
srv \- 9P file service
|
||||
threadpostsrv,
|
||||
threadsrv,
|
||||
threadsrvforker - 9P file service
|
||||
.SH SYNOPSIS
|
||||
.ft L
|
||||
.nf
|
||||
|
@ -59,6 +64,8 @@ typedef struct Srv {
|
|||
int infd;
|
||||
int outfd;
|
||||
int srvfd;
|
||||
|
||||
void (*forker)(void (*fn)(void*), void *arg, int flags);
|
||||
} Srv;
|
||||
.fi
|
||||
.PP
|
||||
|
@ -66,12 +73,17 @@ typedef struct Srv {
|
|||
.ft L
|
||||
.ta \w'\fLvoid* 'u
|
||||
void srv(Srv *s)
|
||||
void postsrv(Srv *s, char *name);
|
||||
void postmountsrv(Srv *s, char *name, char *mtpt, int flag)
|
||||
void postsharesrv(Srv *s, char *name, char *mtpt, char *desc)
|
||||
void listensrv(Srv *s, char *addr)
|
||||
void threadsrv(Srv *s)
|
||||
void threadpostsrv(Srv *s, char *name);
|
||||
void threadpostmountsrv(Srv *s, char *name, char *mtpt, int flag)
|
||||
void threadpostsharesrv(Srv *s, char *name, char *mtpt, char *desc)
|
||||
void listensrv(Srv *s, char *addr)
|
||||
void threadlistensrv(Srv *s, char *addr)
|
||||
void srvforker(void (*fn)(void*), void *arg, int flags)
|
||||
void threadsrvforker(void (*fn)(void*), void *arg, int flags)
|
||||
void respond(Req *r, char *error)
|
||||
void responderror(Req*)
|
||||
void readstr(Req *r, char *src)
|
||||
|
@ -106,7 +118,9 @@ extern int chatty9p;
|
|||
.SH DESCRIPTION
|
||||
The function
|
||||
.I srv
|
||||
serves a 9P session by reading requests from
|
||||
and
|
||||
.I threadsrv
|
||||
serve a 9P session by reading requests from
|
||||
.BR s->infd ,
|
||||
dispatching them to the function pointers kept in
|
||||
.BR Srv ,
|
||||
|
@ -166,6 +180,19 @@ but abort the program if they run out of memory.
|
|||
If alternate behavior is desired, clients can link against
|
||||
alternate implementations of these functions.
|
||||
.PP
|
||||
The functions
|
||||
.I srvforker
|
||||
and
|
||||
.I threadsrvforker
|
||||
handle the creation of new processes on a connection which use
|
||||
.I rfork
|
||||
(see
|
||||
.IR fork (2))
|
||||
or
|
||||
.I procrfork
|
||||
(see
|
||||
.IR thread (2)).
|
||||
.PP
|
||||
.I Postmountsrv
|
||||
and
|
||||
.I threadpostmountsrv
|
||||
|
@ -174,6 +201,14 @@ are wrappers that create a separate process in which to run
|
|||
They do the following:
|
||||
.IP
|
||||
Initialize
|
||||
.IB s -> forker
|
||||
to eigther
|
||||
.I srvforker
|
||||
or
|
||||
.I threadsrvforker
|
||||
unless already initialized to a non-nil value.
|
||||
.IP
|
||||
Initialize
|
||||
.IB s -> infd
|
||||
and
|
||||
.IB s -> outfd
|
||||
|
@ -187,16 +222,12 @@ If
|
|||
is non-nil, post the file descriptor
|
||||
.IB s -> srvfd
|
||||
under the name
|
||||
.BI /srv/ name .
|
||||
.BI /srv/ name
|
||||
using a call to
|
||||
.IR postsrv .
|
||||
.IP
|
||||
Fork a child process via
|
||||
.I rfork
|
||||
(see
|
||||
.IR fork (2))
|
||||
or
|
||||
.I procrfork
|
||||
(see
|
||||
.IR thread (2)),
|
||||
.IB s -> forker
|
||||
using the
|
||||
.BR RFPROC ,
|
||||
.BR RFNOWAIT ,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue