src/sys/pm/name/main.c
/**
 * @brief Handles remote name requests.
 *
 * @returns Always returns 0.
 */
@brief Handles remote name requests.
@returns Always returns 0.
@brief Handles remote name requests . @returns Always returns 0 .
int do_name_server(void)
{
	int tmp;
	int source;
	int shutdown = 0;
	uprintf("[nanvix][name] booting up server");
	do_name_init();
	while (!shutdown)
	{
		struct name_message msg;
		uassert(kmailbox_read(inbox, &msg, sizeof(struct name_message)) == sizeof(struct name_message));
		name_debug("received request opcode=%d", msg.header.opcode);
		switch (msg.header.opcode)
		{
			case NAME_LOOKUP:
				stats.nlookups++;
				msg.nodenum = do_name_lookup(msg.name);
				source = kmailbox_open(msg.header.source);
				uassert(source >= 0);
				uassert(kmailbox_write(source, &msg, sizeof(struct name_message)) == sizeof(struct name_message));
				uassert(kmailbox_close(source) == 0);
				break;
			case NAME_LINK:
				stats.nlinks++;
				tmp = nr_registration;
				if (do_name_link(msg.nodenum, msg.name) == (tmp + 1))
					msg.header.opcode = NAME_SUCCESS;
				else
					msg.header.opcode = NAME_FAIL;
				uassert(nr_registration >= 0);
				source = kmailbox_open(msg.header.source);
				uassert(source >= 0);
				uassert(kmailbox_write(source, &msg, sizeof(struct name_message)) == sizeof(struct name_message));
				uassert(kmailbox_close(source) == 0);
				break;
			case NAME_UNLINK:
				stats.nunlinks++;
				tmp = nr_registration;
				if ((tmp > 0) && (do_name_unlink(msg.name) == (tmp - 1)))
					msg.header.opcode = NAME_SUCCESS;
				else
					msg.header.opcode = NAME_FAIL;
				uassert(nr_registration >= 0);
				source = kmailbox_open(msg.header.source);
				uassert(source >= 0);
				uassert(kmailbox_write(source, &msg, sizeof(struct name_message)) == sizeof(struct name_message));
				uassert(kmailbox_close(source) == 0);
				break;
			case NAME_EXIT:
				shutdown = 1;
				break;
			default:
				break;
		}
	}
	uprintf("[nanvix][name] shutting down server");
	return (0);
}
int do_name_server ( void ) { int tmp ; int source ; int shutdown = 0 ; uprintf ( " " ) ; do_name_init ( ) ; while ( ! shutdown ) { struct name_message msg ; uassert ( kmailbox_read ( inbox , & msg , sizeof ( struct name_message ) ) == sizeof ( struct name_message ) ) ; name_debug ( " " , msg . header . opcode ) ; switch ( msg . header . opcode ) { case NAME_LOOKUP : stats . nlookups ++ ; msg . nodenum = do_name_lookup ( msg . name ) ; source = kmailbox_open ( msg . header . source ) ; uassert ( source >= 0 ) ; uassert ( kmailbox_write ( source , & msg , sizeof ( struct name_message ) ) == sizeof ( struct name_message ) ) ; uassert ( kmailbox_close ( source ) == 0 ) ; break ; case NAME_LINK : stats . nlinks ++ ; tmp = nr_registration ; if ( do_name_link ( msg . nodenum , msg . name ) == ( tmp + 1 ) ) msg . header . opcode = NAME_SUCCESS ; else msg . header . opcode = NAME_FAIL ; uassert ( nr_registration >= 0 ) ; source = kmailbox_open ( msg . header . source ) ; uassert ( source >= 0 ) ; uassert ( kmailbox_write ( source , & msg , sizeof ( struct name_message ) ) == sizeof ( struct name_message ) ) ; uassert ( kmailbox_close ( source ) == 0 ) ; break ; case NAME_UNLINK : stats . nunlinks ++ ; tmp = nr_registration ; if ( ( tmp > 0 ) && ( do_name_unlink ( msg . name ) == ( tmp - 1 ) ) ) msg . header . opcode = NAME_SUCCESS ; else msg . header . opcode = NAME_FAIL ; uassert ( nr_registration >= 0 ) ; source = kmailbox_open ( msg . header . source ) ; uassert ( source >= 0 ) ; uassert ( kmailbox_write ( source , & msg , sizeof ( struct name_message ) ) == sizeof ( struct name_message ) ) ; uassert ( kmailbox_close ( source ) == 0 ) ; break ; case NAME_EXIT : shutdown = 1 ; break ; default : break ; } } uprintf ( " " ) ; return ( 0 ) ; }
@brief Handles remote name requests.
@brief Handles remote name requests .
/* Handle name requests. */ /* Lookup. */ /* Send response. */ /* Add name. */ /* Send acknowledgement. */ /* Remove name. */ /* Send acknowledgement. */ /* Should not happen. */