5 Author: Pekka Riikonen <priikone@silcnet.org>
7 Copyright (C) 2008 Pekka Riikonen
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; version 2 of the License.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
20 /****h* silcutil/Local Network Stream Interface
24 * Local network stream interface enables two or more processes to communicate
25 * with each other in the local machine using the local network. The
26 * interface provides a form of interprocess communication (IPC) using network
29 * Since the implementation uses real TCP network socket the listener can be
30 * used for any TCP communication, however connections may be estalished only
31 * from the local machine. The connections use the loopback network.
36 * listener = silc_local_net_create_listener("/tmp/conn1", 0, schedule,
37 * accept_callback, ctx);
39 * // Connect to the listener
40 * silc_local_net_connect("/tmp/conn1", schedule, connected_callback, ctx);
43 * silc_local_net_close_listener(listener);
47 #ifndef SILCLOCALNETSTREAM_H
48 #define SILCLOCALNETSTREAM_H
50 /****d* silcutil/SilcLocalNetSecurity
54 * typedef enum { ... } SilcLocalNetSecurity
58 * The security flags for the local network listener. They specify
59 * how the listener can be accessed. The flags are a bitmasks and can
60 * be combined. Note that, these flags apply only when this API is
61 * used. Anyone in local machine is able to see the network listener
62 * port by checking all bound network listeners and thus are able to
68 SILC_LOCAL_NET_ALL = 0x0000, /* Anyone in local machine can connect */
69 SILC_LOCAL_NET_USER = 0x0001, /* Same user can connect */
70 SILC_LOCAL_NET_GROUP = 0x0002, /* Same group can connect */
71 } SilcLocalNetSecurity;
74 /****f* silcutil/silc_local_net_create_listener
79 * silc_local_net_create_listener(const char *filepath,
80 * SilcLocalNetSecurity security,
81 * SilcSchedule schedule,
82 * SilcNetCallback callback,
87 * Creates a local network stream listener and returns a network server.
88 * The `filepath' is a local filepath that must be used by the clients to
89 * connect to the server. The `security' specify the access method to
90 * the listener. It can specify for example that only the user creating
91 * the listener is able to connect to it.
93 * The `callback' will be called when a client connects to the listener
94 * with the `context'. The returned stream to the `callback' is a
95 * socket stream (silcsocketstream.h). The returned listener must be
96 * closed by calling silc_local_net_close_listener.
98 * Clients can connect to the listener by calling the
99 * silc_local_net_connect.
101 * Returns NULL on error and set silc_errno. If `schedule' is NULL this
102 * will call silc_schedule_get_global to try to get global scheduler.
105 SilcNetListener silc_local_net_create_listener(const char *filepath,
106 SilcLocalNetSecurity security,
107 SilcSchedule schedule,
108 SilcNetCallback callback,
111 /****f* silcutil/silc_local_net_close_listener
115 * void silc_local_net_close_listener(SilcNetListener local_listener);
119 * Closes the local network stream listener.
122 void silc_local_net_close_listener(SilcNetListener local_listener);
124 /****f* silcutil/silc_local_net_connect
128 * SilcAsyncOperation silc_local_net_connect(const char *filepath,
129 * SilcSchedule schedule,
130 * SilcNetCallback callback,
135 * Connects to the local network server at the provided `filepath'. If
136 * the `filepath' does not exist or is not valid local network listener
137 * the connection will fail.
139 * The `callback' with `context' will be called once the connection has
140 * been created. The stream returned to `callback' is a socket stream
141 * (silcsocketstream.h). SilcStream API can be used with the returned
142 * stream. The stream must be destroyed by calling silc_stream_destroy.
144 * If `schedule' is NULL this will call silc_schedule_get_global to try
145 * to get global scheduler.
148 SilcAsyncOperation silc_local_net_connect(const char *filepath,
149 SilcSchedule schedule,
150 SilcNetCallback callback,
153 #endif /* SILCLOCALNETSTREAM_H */