PadicoTM

Documentation

« back to PM2 home.
vlink-sf.c
Go to the documentation of this file.
1/*
2 * Padico -- a High Performance Parallel and Distributed Computing Environment
3 * Copyright (c) 2002-2025 INRIA and the University of Rennes 1
4 * Alexandre DENIS <Alexandre.Denis@inria.fr>
5 * Christian PEREZ <Christian.Perez@inria.fr>
6 *
7 * The software has been registered at the Agency for the Protection of
8 * Programs (APP) under the number IDDN.FR.001.260013.000.S.P.2002.000.10000.
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 */
24
29#include <Padico/VLink-internals.h>
30#include <Padico/Module.h>
31#include <Padico/SysIO.h>
32#include <Padico/SocketFactory.h>
33
34static int vlink_socketfactory_module_init(void);
35
37 "VIO", "SysIO", "Topology");
38
43/* ********************************************************* */
44
46static int vlink_sf_bind (padico_vnode_t);
52
57 {
59 .bind = &vlink_sf_bind,
60 .listen = &vlink_sf_listen,
61 .connect = &vlink_sf_connect,
62 .fullshutdown = &vlink_sf_fullshutdown,
63 .close = &vlink_sf_close,
64 .dumpstat = &vlink_sf_dumpstat,
65 .send_post = &vnode_hfd_write_post,
66 .recv_post = &vnode_hfd_read_post
67 };
68
77
78static void vlink_sf_connect_finalizer(void*_vnode, int status);
79static void vlink_sf_accept_finalizer(void*key, int new_fd, const struct sockaddr*addr, socklen_t addrlen);
80
81
82/* ********************************************************* */
83
85{
86 puk_component_declare("VLink_SocketFactory",
87 puk_component_provides("PadicoComponent", "component", &padico_vnode_component_driver),
89 puk_component_uses("SocketFactory", "sf"));
90 return 0;
91}
92
93/* ********************************************************* */
94
99{
103 vnode_check(vnode, socket);
108 padico_out(40, "vnode=%p; create() family=%d; type=%d; protocol=%d; rc=%d (%s)\n",
111 if(rc < 0)
112 {
114 rc = -1;
116 }
117 return rc;
118}
119
121{
123 if(vnode_is_sf(vnode))
124 {
125 rc = padico_rc_msg(" <socket-factory fd=\"%d\"/>\n", vnode->hfd.fd);
126 }
127 return rc;
128}
129
131{
132 vnode_check(vnode, socket);
133 vnode_check(vnode, binding);
134 padico_out(30, "vnode=%p\n", vnode);
136 {
137 vnode->binding.primary_len = sizeof(struct sockaddr_pa);
142 }
146 if(rc < 0)
147 {
148 padico_out(20, "vnode=%p bind() rc=%d (%s)\n", vnode, rc, strerror(-rc));
150 rc = -1;
151 }
152
153 return rc;
154}
155
157{
158 const int backlog = vnode->listener.backlog_size;
159 const struct padico_vaddr_s*src_addr = vnode->listener.src_addr;
160 padico_out(50, "backlog=%d\n", backlog);
161 vnode_check(vnode, socket);
164 int rc = (*sf->driver->listen)(sf->_status, backlog, src_addr?src_addr->addr:NULL, src_addr?src_addr->addrlen:0,
166 if(rc < 0)
167 {
169 rc = -1;
170 }
171 return rc;
172}
173
175{
176 int rc = -1, err = 0;
177 if(vnode->content.hfd)
178 {
179 const padico_io_t io_read = vnode->hfd.io_read;
181 const padico_io_t io_write = vnode->hfd.io_write;
183 padico_out(60, "vnode=%p hfd=%d\n", vnode, vnode->hfd.fd);
185 if(io_read)
186 {
188 padico_io_deactivate(io_read);
189 padico_io_unregister(io_read);
191 }
192 if(io_write)
193 {
195 padico_io_deactivate(io_write);
196 padico_io_unregister(io_write);
198 }
200 err = (rc != 0) ? __puk_abi_wrap__errno : 0;
202 }
203}
204
206{
207 int rc = 0;
209 {
210 vnode_check(vnode, socket);
213 rc = (*sf->driver->close)(sf->_status);
214 if(vnode->content.hfd)
215 {
217 }
218 }
219 else if(vnode->content.hfd)
220 {
223 }
224 return rc;
225}
226
232{
233 struct sockaddr*addr;
234 socklen_t addrlen = 0;
235 int rc = -1, err = 0;
236
237 vnode_check(vnode, socket);
238 vnode_check(vnode, hfd);
239 padico_out(50, "vnode=%p\n", vnode);
240 switch(vnode->socket.so_family)
241 {
242 case AF_INET:
243 addrlen = sizeof(struct sockaddr_in);
244 break;
245 case AF_INET6:
246 addrlen = sizeof(struct sockaddr_in6);
247 break;
248 case AF_UNIX:
249 addrlen = sizeof(struct sockaddr_un);
250 break;
251 default:
252 padico_warning("getsockname() on a socket in an unknown domain (domain=%d)\n",
254 }
255 addr = padico_malloc(addrlen);
256 rc = PUK_ABI_FSYS_WRAP(getsockname)(vnode->hfd.fd, addr, &addrlen);
258 if(rc)
259 {
260 padico_warning("error in getsockname()- errno=%d (%s)\n", err, strerror(err));
261 }
262 else
263 {
264 vnode_activate(vnode, binding);
265 vnode->binding.primary = addr;
266 vnode->binding.primary_len = addrlen;
267 }
268 padico_out(50, "vnode=%p- exit\n", vnode);
269}
270
272{
273 vnode_check(vnode, socket);
279 if(rc == -EINPROGRESS)
280 {
281 padico_out(60, "errno=EINPROGRESS\n");
282 }
283 else if(rc < 0)
284 {
285 padico_out(10, "errno=%d (%s)\n", -rc, strerror(-rc));
286 }
287 return (rc==0)?0:-1;
288}
289
290
291/* ** Notification functions ******************************* */
292
295static void vlink_sf_connect_finalizer(void*_vnode, int status)
296{
298 int fd = status;
299 assert(status >= 0);
300 /* detect race condition- close() may have been call on this socket in-between */
302 {
306 vnode->status.writable = 1;
309 }
310}
311
312
315static void vlink_sf_accept_finalizer(void*_vnode, int status, const struct sockaddr*addr, socklen_t addrlen)
316{
319 /* detect race condition- close() may have been call on this socket in-between */
321 {
324 {
326 }
327 if(status < 0)
328 {
329 const int err = -status;
331 padico_out(40, "error errno=%d (%s)\n", err, strerror(err));
332 }
333 else
334 {
335 const int new_fd = status;
336 padico_out(40, "vnode=%p new_fd=%d\n", vnode, new_fd);
340 /* release the lock since vnode_hfd_* functions may take NetAccess SysIO lock,
341 * causing a lock order inversion ifever a callback arrives at the same time.
342 */
344 vnode_hfd_create(newsock, new_fd, O_RDWR);
345 vlink_sf_getsockname(newsock);
347 /* remote binding, enqueue and signal */
348 padico_vsock_acceptor_finalize(newsock, vnode, addr, addrlen);
349 }
350 }
352}
assert(slab_size > 0)
const const struct ns_rule_bucket_s * key
return NULL
Definition Shm.h:88
static void puk_instance_context_indirect_SocketFactory(puk_instance_t instance, const char *label, struct puk_receptacle_SocketFactory_s *receptacle)
static int done
Definition console-mod.c:49
puk_instance_t instance
the listening bootstrap instance
static int fd
Definition datacheck.c:32
#define PUK_ABI_FSYS_WRAP(SYM)
Definition PadicoTM.h:88
padico_rc_t rc
Definition PadicoTM.h:146
#define __puk_abi_wrap__errno
Definition PadicoTM.h:101
void padico_io_unregister(padico_sysio_t io)
Unregister the I/O handle.
Definition sysio.c:298
#define padico_io_t
for backwards compatibility with legacy codes
Definition SysIO.h:53
void padico_io_deactivate(padico_sysio_t io)
Deactivate the I/O handle - should be used for temporarly deactivate callback trigger.
Definition sysio.c:288
void padico_sockaddr_init(struct sockaddr_pa *addr, socklen_t *addrlen, int magic)
Definition topology.c:329
#define AF_PADICO_AUTO
Definition Topology.h:427
volatile int shutdown
Definition na-control.c:84
struct puk_receptacle_SocketFactory_s sf
int(* create)(void *_status, int family, int type, int protocol)
create the socket attached to the SocketFactory instance
int(* listen)(void *_status, int backlog, const struct sockaddr *addr, socklen_t addrlen, padico_socketfactory_acceptor_t notifier, void *key)
listens incoming connections on the socket
int(* connect)(void *_status, const struct sockaddr *addr, socklen_t addrlen, padico_socketfactory_connector_t notifier, void *key)
connects the socket to the given address
int(* close)(void *_status)
closes the given socket
unsigned caps
socket capabilities (
int(* bind)(void *_status, struct sockaddr *addr, socklen_t *addrlen)
binds the socket to the given address (expected: AF_INET family) or performs autobind (AF_PADICO fami...
socklen_t addrlen
Definition Topology.h:463
struct sockaddr * addr
Definition Topology.h:462
virtual node descriptor, common to any file type
Definition VLink-API.h:383
struct vobs_attr_binding_s binding
Definition VLink-API.h:400
struct vobs_attr_socket_s socket
Definition VLink-API.h:398
struct vobs_attr_remote_s remote
Definition VLink-API.h:399
struct padico_vnode_content_t content
Definition VLink-API.h:392
struct vnode_hfd_s hfd
Definition VLink-API.h:402
struct vobs_attr_listener_s listener
Definition VLink-API.h:401
volatile struct vobs_attr_status_s status
Definition VLink-API.h:393
struct padico_socketfactory_s * driver
int fd
associated file descriptor
Definition VLink-API.h:354
padico_sysio_t io_write
Definition VLink-API.h:356
padico_sysio_t io_read
Definition VLink-API.h:355
int autobind
auto-bind request: padico_vsock_bind() will allocate a new address
Definition VLink-API.h:213
socklen_t primary_len
Definition VLink-API.h:212
struct sockaddr * primary
Definition VLink-API.h:211
int backlog_size
max size of the backlog queue
Definition VLink-API.h:224
const struct padico_vaddr_s * src_addr
Definition VLink-API.h:225
padico_vnode_queue_t backlog
incoming connections queue.
Definition VLink-API.h:223
socklen_t remote_addrlen
Definition VLink-API.h:233
struct sockaddr * remote_addr
Definition VLink-API.h:232
int so_protocol
specific protocol
Definition VLink-API.h:204
unsigned capabilities
socket capabilities exposed by the driver (bitmask) [read-only for the user]
Definition VLink-API.h:196
int so_type
protocol type (SOCK_STREAM, SOCK_DGRAM,...)
Definition VLink-API.h:203
int so_family
network family (AF_INET,...)
Definition VLink-API.h:202
unsigned writable
immediate 'write' will not block
Definition VLink-API.h:156
padico_event_listener_t listener