Plan 9 from Bell Labs’s /usr/web/sources/contrib/nemo/sys/src/libomero/port.c

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


#include <u.h>
#include <libc.h>
#include <thread.h>
#include <bio.h>
#include <omero.h>
#include <auth.h>
#include <plumb.h>

typedef struct Arg Arg;

struct Arg {
	int	fd;
	Channel*c;
};

int
createport(char* name)
{
	int	fd;
	char*	fname;

	fname = smprint("/devs/ports/%s", name);
	assert(fname);
	if (access(fname, AREAD) >= 0)
		fd = open(fname, OREAD|OCEXEC);
	else
		fd = create(fname, OREAD|OCEXEC, 0660);
	free(fname);
	return fd;
}

static void
plumbproc(void* a)
{
	Arg*	p;
	Plumbmsg *m;

	threadsetname("plumbproc");
	p = a;
	for(;;){
		m = plumbrecv(p->fd);
		sendp(p->c, m);
		if(m == nil)
			break;
	}
	threadexits(nil);
}

Channel*
createportproc(char* port)
{
	Arg*	a;
	int	fd;

	fd = createport(port);
	if (fd < 0)
		return nil;
	a = malloc(sizeof(Arg));
	assert(a);
	a->fd = fd;
	a->c = chancreate(sizeof(Plumbmsg*), 0);
	proccreate(plumbproc, a, 8*1024);
	return a->c;
}

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to [email protected].