source: mainline/uspace/srv/ns/ns.c@ eec201d

Last change on this file since eec201d was f5837524, checked in by Jakub Jermar <jakub@…>, 7 years ago

Use user-defined labels instead of phone hashes

This commit changes the way how the async framework maps incomming calls
to connections. Instead of abusing the kernel addresses of attached
phones as identifiers, the IPC_M_CONNECT_TO_ME and IPC_M_CONNECT_ME_TO
messages allow the server to specify an arbitrary label which is
remembered in the connected phone and consequently imprinted on each
call which is routed through this phone.

The async framework uses the address of the connection structure as the
label. This removes the need for a connection hash table because each
incoming call already remembers the connection in its label.

To disambiguate this new label and the other user-defined label used for
answers, the call structure now has the request_label member for the
former and answer_label member for the latter.

This commit also moves the kernel definition of ipc_data_t to abi/ and
removes the uspace redefinition thereof. Finally, when forwarding the
IPC_M_CONNECT_TO_ME call, the phone capability and the kernel object
allocated in request_process are now correctly disposed of.

  • Property mode set to 100644
File size: 3.8 KB
Line 
1/*
2 * Copyright (c) 2006 Ondrej Palkovsky
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/** @addtogroup ns
30 * @{
31 */
32
33/**
34 * @file ns.c
35 * @brief Naming service for HelenOS IPC.
36 */
37
38#include <abi/ipc/methods.h>
39#include <async.h>
40#include <ipc/ns.h>
41#include <ipc/services.h>
42#include <abi/ipc/interfaces.h>
43#include <stdio.h>
44#include <errno.h>
45#include <macros.h>
46#include "ns.h"
47#include "service.h"
48#include "clonable.h"
49#include "task.h"
50
51static void ns_connection(ipc_call_t *icall, void *arg)
52{
53 ipc_call_t call;
54 iface_t iface;
55 service_t service;
56
57 iface = IPC_GET_ARG1(*icall);
58 service = IPC_GET_ARG2(*icall);
59 if (service != 0) {
60 /*
61 * Client requests to be connected to a service.
62 */
63 if (ns_service_is_clonable(service, iface)) {
64 ns_clonable_forward(service, iface, icall);
65 } else {
66 ns_service_forward(service, iface, icall);
67 }
68
69 return;
70 }
71
72 async_answer_5(icall, EOK, 0, 0, 0, 0, async_get_label());
73
74 while (true) {
75 ns_pending_conn_process();
76
77 async_get_call(&call);
78 if (!IPC_GET_IMETHOD(call))
79 break;
80
81 task_id_t id;
82 errno_t retval;
83
84 service_t service;
85
86 switch (IPC_GET_IMETHOD(call)) {
87 case NS_REGISTER:
88 service = IPC_GET_ARG1(call);
89 iface = IPC_GET_ARG2(call);
90
91 /*
92 * Server requests service registration.
93 */
94 if (ns_service_is_clonable(service, iface)) {
95 ns_clonable_register(&call);
96 continue;
97 } else {
98 retval = ns_service_register(service, iface);
99 }
100
101 break;
102 case NS_REGISTER_BROKER:
103 service = IPC_GET_ARG1(call);
104 retval = ns_service_register_broker(service);
105 break;
106 case NS_PING:
107 retval = EOK;
108 break;
109 case NS_TASK_WAIT:
110 id = (task_id_t)
111 MERGE_LOUP32(IPC_GET_ARG1(call), IPC_GET_ARG2(call));
112 wait_for_task(id, &call);
113 continue;
114 case NS_ID_INTRO:
115 retval = ns_task_id_intro(&call);
116 break;
117 case NS_RETVAL:
118 retval = ns_task_retval(&call);
119 break;
120 default:
121 printf("%s: Method not supported (%" PRIun ")\n",
122 NAME, IPC_GET_IMETHOD(call));
123 retval = ENOTSUP;
124 break;
125 }
126
127 async_answer_0(&call, retval);
128 }
129
130 (void) ns_task_disconnect(&call);
131 async_answer_0(&call, EOK);
132}
133
134int main(int argc, char **argv)
135{
136 printf("%s: HelenOS IPC Naming Service\n", NAME);
137
138 errno_t rc = ns_service_init();
139 if (rc != EOK)
140 return rc;
141
142 rc = ns_clonable_init();
143 if (rc != EOK)
144 return rc;
145
146 rc = task_init();
147 if (rc != EOK)
148 return rc;
149
150 async_set_fallback_port_handler(ns_connection, NULL);
151
152 printf("%s: Accepting connections\n", NAME);
153 async_manager();
154
155 /* Not reached */
156 return 0;
157}
158
159/**
160 * @}
161 */
Note: See TracBrowser for help on using the repository browser.