openblt

a hobby OS from the late 90s
git clone http://frotz.net/git/openblt.git
Log | Files | Refs | LICENSE

tell.c (1014B)


      1 /* Copyright 1999, Sidney Cammeresi. All rights reserved.
      2 ** Distributed under the terms of the OpenBLT License
      3 */
      4 
      5 #include <stdio.h>
      6 #include <stdlib.h>
      7 #include <string.h>
      8 #include <blt/syscall.h>
      9 #include <blt/libsyms.h>
     10 #include <blt/namer.h>
     11 #include <blt/tell.h>
     12 
     13 static char *name;
     14 static volatile int ready = 0;
     15 static void (*callback)(const char *);
     16 
     17 weak_alias (_tell_init, tell_init)
     18 
     19 void __tell_impl (void)
     20 {
     21 	char *buf, junk;
     22 	int port, len;
     23 	msg_hdr_t mh;
     24 
     25 	port = port_create (0, "tell_listen_port");
     26 	buf = malloc (len = TELL_MAX_LEN);
     27 	strlcpy (buf, name, len);
     28 	strlcat (buf, ":tell", len);
     29 	namer_register (port, buf);
     30 	ready = 1;
     31 
     32 	for (;;)
     33 	{
     34 		mh.src = 0;
     35 		mh.dst = port;
     36 		mh.data = buf;
     37 		mh.size = len;
     38 		old_port_recv (&mh);
     39 		(*callback) (buf);
     40 		mh.dst = mh.src;
     41 		mh.src = port;
     42 		mh.data = &junk;
     43 		mh.size = 1;
     44 		old_port_send (&mh);
     45 	}
     46 }
     47 
     48 int _tell_init (char *n, void (*c)(const char *))
     49 {
     50 	name = n;
     51 	callback = c;
     52 	os_thread (__tell_impl);
     53 	while (!ready) ;
     54 	return ready;
     55 }
     56