PadicoTM

Documentation

« back to PM2 home.
SysIO: shared polling for file descriptors

Files

file  sysio.c
 System I/O management.
 

Macros

#define padico_io_t   padico_sysio_t
 for backwards compatibility with legacy codes
 
#define PADICO_IO_EVENT_READ   0x01
 the fildes is readable
 
#define PADICO_IO_EVENT_WRITE   0x02
 the fildes is writable
 
#define PADICO_IO_EVENT_ERROR   0x04
 the fildes has an error
 

Typedefs

typedef struct padico_sysio_s * padico_sysio_t
 a NetAccess I/O handle
 
typedef int(* padico_sysio_callback_t) (int fd, void *key)
 a NetAccess SysIO callback
 

Functions

padico_sysio_t padico_io_register (int fd, unsigned int what, padico_sysio_callback_t callback, void *key)
 Registers a file descriptor for polling.
 
void padico_io_unregister (padico_sysio_t)
 Unregister the I/O handle.
 
void padico_io_activate (padico_sysio_t)
 Activates the I/O handle - when not activated, the callback is not triggered.
 
void padico_io_deactivate (padico_sysio_t)
 Deactivate the I/O handle - should be used for temporarly deactivate callback trigger.
 
int padico_sysio_refresh (padico_sysio_t io)
 Waits until at least one polling/callback cycle has been performed on the I/O handle.
 
int padico_sysio_getfd (padico_sysio_t io)
 
padico_rc_t padico_sysio_stat (void)
 dump internal status of SysIO
 
int padico_sysio_socket (int domain, int type, int protocol)
 
ssize_t padico_sysio_read (int fildes, void *buf, ssize_t nbyte)
 
ssize_t padico_sysio_write (int fildes, const void *buf, ssize_t nbyte)
 
ssize_t padico_sysio_writev (int fildes, const struct iovec *iov, int iovcnt)
 
int padico_sysio_bound_inet_socket (int *port)
 
int padico_sysio_connected_inet_socket (const struct in_addr *, int port)
 
int padico_sysio_connected_inet_socket_sockaddr (const struct sockaddr *addr)
 
ssize_t padico_sysio_in (int fildes, void *buf, size_t nbyte)
 
ssize_t padico_sysio_out (int fildes, const void *buf, size_t nbyte)
 
ssize_t padico_sysio_outv (int fildes, const struct iovec *buf, int iovcnt)
 
int padico_sysio_eos (int fd)
 
int padico_sysio_shutdown_wr (int s)
 
int padico_sysio_close (int fd)
 
int padico_sysio_accept (int s, struct sockaddr *addr, socklen_t *addrlen)
 
int padico_sysio_errno (void)
 

Detailed Description

Macro Definition Documentation

◆ PADICO_IO_EVENT_ERROR

#define PADICO_IO_EVENT_ERROR   0x04

the fildes has an error

Definition at line 64 of file SysIO.h.

◆ PADICO_IO_EVENT_READ

#define PADICO_IO_EVENT_READ   0x01

the fildes is readable

Definition at line 62 of file SysIO.h.

◆ PADICO_IO_EVENT_WRITE

#define PADICO_IO_EVENT_WRITE   0x02

the fildes is writable

Definition at line 63 of file SysIO.h.

◆ padico_io_t

#define padico_io_t   padico_sysio_t

for backwards compatibility with legacy codes

Definition at line 53 of file SysIO.h.

Typedef Documentation

◆ padico_sysio_callback_t

typedef int(* padico_sysio_callback_t) (int fd, void *key)

a NetAccess SysIO callback

  • fd the file descriptor on which the event happened
  • key a key given at registration of the callback
    Returns
    1 to keep the callback registered, 0 to cancel

Definition at line 60 of file SysIO.h.

◆ padico_sysio_t

a NetAccess I/O handle

Definition at line 50 of file SysIO.h.

Function Documentation

◆ padico_io_activate()

◆ padico_io_deactivate()

void padico_io_deactivate ( padico_sysio_t  io)

◆ padico_io_register()

padico_sysio_t padico_io_register ( int  fd,
unsigned int  what,
padico_sysio_callback_t  callback,
void *  key 
)

Registers a file descriptor for polling.

Parameters
fdFile descriptor (should already exist)
whatThe operation that triggers callback – several bits may be OR-ed
callbackThe callback function that will be called uppon I/O event
keyan argument that will be given to the callback
Returns
an I/O handle for future reference
Note
after registration, the I/O handle is not activated
Bug:
Some troubles in this implementation... Since padico_io_t are static pointers into a dynamic vector, we must be sure that the I/O vector is never resized! It's too strong a constraint for scalability. Static assertions about a dynamic vector are obviously not the way to go. It's enough for testing, though...

Definition at line 205 of file sysio.c.

References padico_sysio_s::activated, assert(), padico_sysio_s::callback, padico_sysio_s::callback_key, done, fd, padico_sysio_s::fd, padico_sysio_mgr_s::ios, key, na_ios, na_sysio_lock(), na_sysio_rebuild_fds(), na_sysio_unlock(), NULL, PADICO_IO_MAX_FD, padico_io_t, padico_sysio_s::status, v, padico_sysio_s::what, and what.

Referenced by bench_sysio_init(), padico_na_sysio_init(), psp_sf_connect(), remote_control_connector(), sflibssh2_connect(), sfplain_bind(), sfplain_connect(), sfrfw_gateway_client_callback_connector(), sfrfw_gateway_server_callback_connector(), sfsnc_connect(), sfsplice_do_splicing(), sfsrtun_create(), sfssh2_connect(), sfstun_create(), socks4client_proxy_connect_notifier(), ssh2_control_start(), sysio_control_start(), tube_gk_init(), vlink_ps_listen(), vnode_hfd_create(), vrp_incoming_construct(), and vrp_outgoing_construct().

◆ padico_io_unregister()

void padico_io_unregister ( padico_sysio_t  io)

Unregister the I/O handle.

Note
even if it is not mandatory, it is better to:
  1. deactivate the io
  2. perform the required synchronisation (check callback completion)
  3. finally, unregister.
Unregister a callback has a high cost. Most of the time, use deactivation; unregister the callback just before closing the file descriptor.
See also
padico_io_deactivate()

Definition at line 298 of file sysio.c.

References assert(), done, na_sysio_lock(), na_sysio_rebuild_fds(), and na_sysio_unlock().

Referenced by remote_control_finalize(), sflibssh2_close(), sflibssh2_destroy(), sfplain_close(), sfrfw_gateway_close(), sfsnc_close(), sfsnc_destroy(), sfsplice_destroy(), sfsrtun_close(), sfssh2_close(), sfssh2_destroy(), sfstun_close(), socks4client_proxy_reply_notifier(), sysio_control_socket_close(), vlink_sf_fullshutdown(), vnode_hfd_close(), vrp_incoming_close(), and vrp_outgoing_close().

◆ padico_sysio_accept()

int padico_sysio_accept ( int  s,
struct sockaddr *  addr,
socklen_t *  addrlen 
)

Definition at line 784 of file sysio.c.

References done, na_sysio_tune_socket(), PUK_ABI_FSYS_WRAP, rc, and s.

Referenced by bench_sysio_init(), and vlink_ps_callback_acceptor().

◆ padico_sysio_bound_inet_socket()

int padico_sysio_bound_inet_socket ( int *  port)

Definition at line 887 of file sysio.c.

References done, int, NULL, padico_sysio_socket(), port, PUK_ABI_FSYS_WRAP, rc, s, and socklen_t.

Referenced by bench_sysio_init().

◆ padico_sysio_close()

◆ padico_sysio_connected_inet_socket()

int padico_sysio_connected_inet_socket ( const struct in_addr *  in_addr,
int  port 
)

Definition at line 841 of file sysio.c.

References done, na_sysio_tune_socket(), padico_sysio_socket(), port, PUK_ABI_FSYS_WRAP, rc, and s.

Referenced by bench_sysio_init().

◆ padico_sysio_connected_inet_socket_sockaddr()

int padico_sysio_connected_inet_socket_sockaddr ( const struct sockaddr *  addr)

◆ padico_sysio_eos()

int padico_sysio_eos ( int  fd)

Definition at line 834 of file sysio.c.

References done, fd, PUK_ABI_FSYS_WRAP, rc, and recv.

◆ padico_sysio_errno()

◆ padico_sysio_getfd()

int padico_sysio_getfd ( padico_sysio_t  io)

Definition at line 312 of file sysio.c.

◆ padico_sysio_in()

◆ padico_sysio_out()

◆ padico_sysio_outv()

ssize_t padico_sysio_outv ( int  fildes,
const struct iovec *  buf,
int  iovcnt 
)

Definition at line 828 of file sysio.c.

References done, padico_sysio_writev(), and rc.

Referenced by ssh2_control_outv(), and sysio_control_send_common().

◆ padico_sysio_read()

◆ padico_sysio_refresh()

int padico_sysio_refresh ( padico_sysio_t  io)

Waits until at least one polling/callback cycle has been performed on the I/O handle.

Definition at line 262 of file sysio.c.

References done, na_sysio_lock(), na_sysio_unlock(), na_sysio_update_status(), and rc.

Referenced by vnode_hfd_read_post(), and vnode_hfd_write_post().

◆ padico_sysio_shutdown_wr()

int padico_sysio_shutdown_wr ( int  s)

Definition at line 768 of file sysio.c.

References done, PUK_ABI_FSYS_WRAP, rc, s, and shutdown.

◆ padico_sysio_socket()

◆ padico_sysio_stat()

padico_rc_t padico_sysio_stat ( void  )

dump internal status of SysIO

Definition at line 1014 of file sysio.c.

References done, padico_na_internal_getios(), padico_sysio_vect_t, rc, and v.

Referenced by padico_sysio_stat_handler().

◆ padico_sysio_write()

◆ padico_sysio_writev()

ssize_t padico_sysio_writev ( int  fildes,
const struct iovec *  iov,
int  iovcnt 
)

Definition at line 688 of file sysio.c.

References __puk_abi_wrap__errno, done, PUK_ABI_FSYS_WRAP, and rc.

Referenced by padico_sysio_outv().