BRL-CAD
Loading...
Searching...
No Matches
pkg.h
Go to the documentation of this file.
1/* P K G . H
2 * BRL-CAD
3 *
4 * Copyright (c) 2004-2026 United States Government as represented by
5 * the U.S. Army Research Laboratory.
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public License
9 * version 2.1 as published by the Free Software Foundation.
10 *
11 * This library is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this file; see the file named COPYING for more
18 * information.
19 */
20/** @addtogroup libpkg */
21/** @{ */
22/** @file pkg.h
23 *
24 * LIBPKG provides routines to manage multiplexing and de-multiplexing
25 * synchronous and asynchronous messages across stream connections.
26 *
27 */
28
29#ifndef PKG_H
30#define PKG_H
31
32#include "common.h"
33
34/* for size_t */
35#include <stddef.h>
36
37#ifndef PKG_EXPORT
38# if defined(PKG_DLL_EXPORTS) && defined(PKG_DLL_IMPORTS)
39# error "Only PKG_DLL_EXPORTS or PKG_DLL_IMPORTS can be defined, not both."
40# elif defined(PKG_DLL_EXPORTS)
41# define PKG_EXPORT COMPILER_DLLEXPORT
42# elif defined(PKG_DLL_IMPORTS)
43# define PKG_EXPORT COMPILER_DLLIMPORT
44# else
45# define PKG_EXPORT
46# endif
47#endif
48
49
50#ifdef __cplusplus
51extern "C" {
52#endif
53
54struct pkg_conn;
55
56typedef void (*pkg_callback)(struct pkg_conn*, char*);
57typedef void (*pkg_errlog)(const char *msg);
58
59struct pkg_switch {
60 unsigned short pks_type; /**< @brief Type code */
61 pkg_callback pks_handler; /**< @brief Message Handler */
62 const char *pks_title; /**< @brief Description of message type */
63 void *pks_user_data; /**< @brief User defined pointer to data */
64};
65
66/**
67 * Format of the message header as it is transmitted over the network
68 * connection. Internet network order is used.
69 * User Code should access pkc_len and pkc_type rather than
70 * looking into the header directly.
71 * Users should never need to know what this header looks like.
72 */
73#define PKG_MAGIC 0x41FE
74struct pkg_header {
75 unsigned char pkh_magic[2]; /**< @brief Ident */
76 unsigned char pkh_type[2]; /**< @brief Message Type */
77 unsigned char pkh_len[4]; /**< @brief Byte count of remainder */
78};
79
80#define PKG_STREAMLEN (32*1024)
81struct pkg_conn {
82 int pkc_fd; /**< @brief TCP connection fd */
83 int pkc_in_fd; /**< @brief input fd for split-fd (pipe) transports */
84 int pkc_out_fd; /**< @brief output fd for split-fd (pipe) transports */
85
86 const struct pkg_switch *pkc_switch; /**< @brief Array of message handlers */
87 pkg_errlog pkc_errlog; /**< @brief Error message logger */
88 struct pkg_header pkc_hdr; /**< @brief hdr of cur msg */
89 size_t pkc_len; /**< @brief pkg_len, in host order */
90 unsigned short pkc_type; /**< @brief pkg_type, in host order */
91 void *pkc_user_data; /**< @brief User defined pointer to data for the current pkg_type */
92 /* OUTPUT BUFFER */
93 char pkc_stream[PKG_STREAMLEN]; /**< @brief output stream */
94 unsigned int pkc_magic; /**< @brief for validating pointers */
95 int pkc_strpos; /**< @brief index into stream buffer */
96 /* FIRST LEVEL INPUT BUFFER */
97 char *pkc_inbuf; /**< @brief input stream buffer */
98 int pkc_incur; /**< @brief current pos in inbuf */
99 int pkc_inend; /**< @brief first unused pos in inbuf */
100 int pkc_inlen; /**< @brief length of pkc_inbuf */
101 /* DYNAMIC BUFFER FOR USER */
102 int pkc_left; /**< @brief # bytes pkg_get expects */
103 /* neg->read new hdr, 0->all here, >0 ->more to come */
104 char *pkc_buf; /**< @brief start of dynamic buf */
105 char *pkc_curpos; /**< @brief current position in pkg_buf */
106 void *pkc_server_data; /**< @brief used to hold server data for callbacks */
107
108 /**
109 * Pluggable I/O layer for TLS (or any other stream cipher / framing).
110 *
111 * When pkc_tls_read / pkc_tls_write are non-NULL they completely
112 * replace the raw fd reads/writes inside pkg_suckin(), pkg_send(),
113 * pkg_2send(), and pkg_flush(). pkc_tls_ctx is the opaque context
114 * pointer forwarded as the first argument to both callbacks.
115 *
116 * pkc_tls_free (if non-NULL) is called by pkg_close() before
117 * closing the socket, giving the TLS layer a chance to send a
118 * clean close_notify and free its own state.
119 *
120 * All four fields are zero-initialized by _pkg_makeconn().
121 *
122 * The callback signatures use ptrdiff_t (always defined via
123 * <stddef.h>) rather than ssize_t to avoid POSIX-only header
124 * dependencies in this public header.
125 */
126 void *pkc_tls_ctx; /**< @brief opaque TLS state (e.g. SSL *) */
127 ptrdiff_t (*pkc_tls_read)(void *ctx, void *buf, size_t n); /**< @brief TLS read callback; NULL = use raw fd */
128 ptrdiff_t (*pkc_tls_write)(void *ctx, const void *buf, size_t n); /**< @brief TLS write callback; NULL = use raw fd */
129 void (*pkc_tls_free)(void *ctx); /**< @brief called by pkg_close() to free TLS state */
130 char pkc_addr[128]; /**< @brief transport address string (populated by future phases) */
131 char pkc_addr_env[160]; /**< @brief PKG_ADDR=... env string for child spawn (future phases) */
132 int pkc_tx_kind; /**< @brief transport kind: 0=socket/TCP, 1=pipe pair */
133 int pkc_listen_fd; /**< @brief listening socket fd for lazy-accept (TCP, future phases) */
134};
135#define PKC_NULL ((struct pkg_conn *)0)
136#define PKC_ERROR ((struct pkg_conn *)(-1L))
137
138
139/**
140 * Sends a VLS as a given message type across a pkg connection.
141 */
142#define pkg_send_vls(type, vlsp, pkg) \
143 pkg_send( (type), bu_vls_addr((vlsp)), bu_vls_strlen((vlsp))+1, (pkg) )
144
145
146/**
147 * Open a network connection to a host/server.
148 *
149 * Returns PKC_ERROR on error.
150 */
151PKG_EXPORT extern struct pkg_conn *pkg_open(const char *host, const char *service, const char *protocol, const char *username, const char *passwd, const struct pkg_switch* switchp, pkg_errlog errlog);
152
153/**
154 * Close a network connection.
155 *
156 * Gracefully release the connection block and close the connection.
157 */
158PKG_EXPORT extern void pkg_close(struct pkg_conn* pc);
159
160PKG_EXPORT extern int pkg_process(struct pkg_conn *);
161
162/**
163 * Suck all data from the operating system into the internal buffer.
164 *
165 * This is done with large buffers, to maximize the efficiency of the
166 * data transfer from kernel to user.
167 *
168 * It is expected that the read() system call will return as much data
169 * as the kernel has, UP TO the size indicated. The only time the
170 * read() may be expected to block is when the kernel does not have
171 * any data at all. Thus, it is wise to call call this routine only
172 * if:
173 *
174 * a) select() has indicated the presence of data, or
175 * b) blocking is acceptable.
176 *
177 * This routine is the only place where data is taken off the network.
178 * All input is appended to the internal buffer for later processing.
179 *
180 * Subscripting was used for pkc_incur/pkc_inend to avoid having to
181 * recompute pointers after a realloc().
182 *
183 * Returns -
184 * -1 on error
185 * 0 on EOF
186 * 1 success
187 */
188PKG_EXPORT extern int pkg_suckin(struct pkg_conn *);
189
190/**
191 * Send a message on the connection.
192 *
193 * Send the user's data, prefaced with an identifying header which
194 * contains a message type value. All header fields are exchanged in
195 * "network order".
196 *
197 * Note that the whole message (header + data) should be transmitted
198 * by TCP with only one TCP_PUSH at the end, due to the use of
199 * writev().
200 *
201 * Returns number of bytes of user data actually sent.
202 */
203PKG_EXPORT extern int pkg_send(int type, const char *buf, size_t len, struct pkg_conn* pc);
204
205/**
206 * Send a two part message on the connection.
207 *
208 * Exactly like pkg_send, except user's data is located in two
209 * disjoint buffers, rather than one. Fiendishly useful!
210 */
211PKG_EXPORT extern int pkg_2send(int type, const char *buf1, size_t len1, const char *buf2, size_t len2, struct pkg_conn* pc);
212
213/**
214 * Send a message that doesn't need a push.
215 *
216 * Exactly like pkg_send except no "push" is necessary here. If the
217 * packet is sufficiently small (MAXQLEN) it will be placed in the
218 * pkc_stream buffer (after flushing this buffer if there insufficient
219 * room). If it is larger than this limit, it is sent via pkg_send
220 * (who will do a pkg_flush if there is already data in the stream
221 * queue).
222 *
223 * Returns number of bytes of user data actually sent (or queued).
224 */
225PKG_EXPORT extern int pkg_stream(int type, const char *buf, size_t len, struct pkg_conn* pc);
226
227/**
228 * Empty the stream buffer of any queued messages.
229 *
230 * Flush any pending data in the pkc_stream buffer.
231 *
232 * Returns < 0 on failure, else number of bytes sent.
233 */
234PKG_EXPORT extern int pkg_flush(struct pkg_conn* pc);
235
236/**
237 * Wait for a specific msg, user buf, processing others.
238 *
239 * This routine implements a blocking read on the network connection
240 * until a message of 'type' type is received. This can be useful for
241 * implementing the synchronous portions of a query/reply exchange.
242 * All messages of any other type are processed by pkg_block().
243 *
244 * Returns the length of the message actually received, or -1 on error.
245 */
246PKG_EXPORT extern int pkg_waitfor(int type, char *buf, size_t len, struct pkg_conn* pc);
247
248/**
249 * Wait for specific msg, malloc buf, processing others.
250 *
251 * This routine implements a blocking read on the network connection
252 * until a message of 'type' type is received. This can be useful for
253 * implementing the synchronous portions of a query/reply exchange.
254 * All messages of any other type are processed by pkg_block().
255 *
256 * The buffer to contain the actual message is acquired via malloc(),
257 * and the caller must free it.
258 *
259 * Returns pointer to message buffer, or NULL.
260 */
261PKG_EXPORT extern char *pkg_bwaitfor(int type, struct pkg_conn* pc);
262
263/**
264 * Wait until a full message has been read.
265 *
266 * This routine blocks, waiting for one complete message to arrive
267 * from the network. The actual handling of the message is done with
268 * _pkg_dispatch(), which invokes the user-supplied message handler.
269 *
270 * This routine can be used in a loop to pass the time while waiting
271 * for a flag to be changed by the arrival of an asynchronous message,
272 * or for the arrival of a message of uncertain type.
273 *
274 * The companion routine is pkg_process(), which does not block.
275 *
276 * Control returns to the caller after one full message is processed.
277 * Returns -1 on error, etc.
278 */
279PKG_EXPORT extern int pkg_block(struct pkg_conn* pc);
280
281/****************************
282 * Transport accessors *
283 ****************************/
284
285/**
286 * Return the file descriptor a caller should pass to select(), poll(),
287 * QSocketNotifier, libuv, etc. for read-readiness notification.
288 *
289 * Hides the distinction between bidirectional sockets (where read and
290 * write share a single fd) and pipe-pair connections (where the read
291 * end is a separate fd kept internally as pkc_in_fd). Callers should
292 * use this in preference to looking at pkc_fd / pkc_in_fd directly.
293 *
294 * Returns -1 on error.
295 */
296PKG_EXPORT extern int pkg_get_read_fd(const struct pkg_conn *pc);
297
298/**
299 * Return the file descriptor used for write-readiness notification.
300 * Equal to pkg_get_read_fd() for bidirectional transports (TCP /
301 * socketpair); for pipe-pair connections this is the write fd.
302 *
303 * Returns -1 on error.
304 */
305PKG_EXPORT extern int pkg_get_write_fd(const struct pkg_conn *pc);
306
307/**
308 * Return non-zero if the connection uses split read/write fds (i.e.
309 * the unidirectional pipe transport; pkc_in_fd != pkc_out_fd).
310 * Use this in preference to inspecting pkc_fd / pkc_in_fd / pkc_out_fd
311 * directly so future transport changes remain source-compatible.
312 */
313PKG_EXPORT extern int pkg_is_stdio_mode(const struct pkg_conn *pc);
314
315/**
316 * Set the kernel send-buffer size on the underlying socket
317 * (equivalent to setsockopt(SOL_SOCKET, SO_SNDBUF)).
318 *
319 * Silently succeeds (returns 0) for transports where send-buffer
320 * tuning is not applicable (pipe / split-fd connections).
321 *
322 * Returns 0 on success, -1 on error.
323 */
324PKG_EXPORT extern int pkg_set_send_buffer(struct pkg_conn *pc, size_t bytes);
325
326/**
327 * Set the kernel receive-buffer size on the underlying socket
328 * (equivalent to setsockopt(SOL_SOCKET, SO_RCVBUF)).
329 *
330 * Silently succeeds (returns 0) for transports where receive-buffer
331 * tuning is not applicable. Returns 0 on success, -1 on error.
332 */
333PKG_EXPORT extern int pkg_set_recv_buffer(struct pkg_conn *pc, size_t bytes);
334
335/**
336 * Set TCP_NODELAY on the underlying socket. No-op on non-TCP
337 * transports. Returns 0 on success, -1 on error.
338 */
339PKG_EXPORT extern int pkg_set_nodelay(struct pkg_conn *pc, int on);
340
341/**
342 * Install a TLS / framing-cipher I/O shim on the connection.
343 *
344 * When @p tls_read / @p tls_write are non-NULL they completely replace
345 * the raw read()/write() calls inside pkg_suckin(), pkg_send(),
346 * pkg_2send(), and pkg_flush(). @p tls_ctx is the opaque context
347 * pointer forwarded as the first argument to both callbacks.
348 *
349 * @p tls_free (if non-NULL) is invoked by pkg_close() before closing
350 * the underlying transport, giving the TLS layer a chance to send a
351 * clean close_notify and free its own state.
352 *
353 * Returns 0 on success, -1 on error.
354 */
356 void *tls_ctx,
357 ptrdiff_t (*tls_read)(void *ctx, void *buf, size_t n),
358 ptrdiff_t (*tls_write)(void *ctx, const void *buf, size_t n),
359 void (*tls_free)(void *ctx));
360
361/**
362 * Wrap an already-connected socket fd in a pkg_conn without performing
363 * any network connect/accept.
364 *
365 * Replaces the historical pattern of allocating a pkg_conn and
366 * hand-initialising pkc_magic / pkc_fd / pkc_switch / pkc_left etc.
367 * Used by callers that obtain a connected socket from another framework
368 * (Tcl/Qt) and want to drive it through libpkg's framing protocol.
369 *
370 * On Windows this also performs WinSock initialisation if necessary.
371 *
372 * Returns a pkg_conn handle on success, PKC_ERROR on failure.
373 */
375 const struct pkg_switch *switchp,
377
378
379/****************************
380 * Transport constants *
381 ****************************/
382
383/** Environment variable read by a child to find its IPC channel address. */
384#define PKG_ADDR_ENVVAR "PKG_ADDR"
385
386/** Optional transport preference hint for pkg_pair(). */
387#define PKG_TRANSPORT_PREFER_ENVVAR "PKG_TRANSPORT_PREFER"
388
389/** Transport type for probing preference. */
390typedef enum {
391 PKG_TRANSPORT_AUTO = 0, /**< @brief Use default probe order */
392 PKG_TRANSPORT_PIPE = 1, /**< @brief Anonymous pipe transport */
393 PKG_TRANSPORT_SOCKET = 2, /**< @brief POSIX socketpair transport */
394 PKG_TRANSPORT_TCP = 3 /**< @brief TCP loopback transport */
396
397
398/****************************
399 * Pair / connect API *
400 ****************************/
401
402/**
403 * Create a connected pair of pkg_conn handles.
404 *
405 * Probe order: pipe -> socketpair -> TCP loopback (or use preferred).
406 * Returns 0 on success, -1 on failure.
407 */
409 struct pkg_conn **child_end,
410 const struct pkg_switch *switchp,
412
414 struct pkg_conn **child_end,
415 const struct pkg_switch *switchp,
418
419/**
420 * Return a "KEY=VALUE" env string for passing to a spawned child.
421 * The pointer is valid until pkg_close(). Format: "PKG_ADDR=<addr>".
422 * For pair transports, the address may be a child-side or parent-side
423 * local IPC string, depending on which end is being exported.
424 */
425PKG_EXPORT extern const char *pkg_child_addr_env(struct pkg_conn *pc);
426
427/**
428 * Return just the raw address string (e.g. "pipe:4,7" or "socket:5")
429 * for use in argv["-I addr"] style arguments to a child process.
430 * Pair transports may also return parent-side variants such as
431 * "pipe_parent:4,7" and "socket_parent:5".
432 * The pointer is valid until pkg_close().
433 */
434PKG_EXPORT extern const char *pkg_child_addr(struct pkg_conn *pc);
435
436/**
437 * Connect an IPC endpoint from an address string.
438 * Supports child-side and parent-side pair addresses, reusable local IPC
439 * listener addresses returned by pkg_ipc_addr(), plus TCP loopback.
440 * Callers should treat local IPC listener addresses as opaque strings.
441 * Returns pkg_conn* on success, PKC_ERROR on failure.
442 */
443PKG_EXPORT extern struct pkg_conn *pkg_connect_addr(const char *addr,
444 const struct pkg_switch *switchp,
446
447/**
448 * Create an opaque local IPC listener address suitable for this process.
449 *
450 * The resulting address string is for local same-host communication and is
451 * intended to be passed unchanged to a server's pkg_listen() and client-side
452 * pkg_connect_addr() calls. It does not bind the listener itself. The
453 * concrete transport is selected by libpkg for the current platform.
454 * Current implementations include POSIX FIFO/UNIX-domain transports and
455 * Windows named pipes; callers must not parse the returned address.
456 * Platforms may support inherited endpoint IPC via pkg_pair() even when
457 * they do not provide a reusable listener transport here.
458 *
459 * Returns 0 on success, -1 if no local listener transport is available.
460 */
461PKG_EXPORT extern int pkg_ipc_addr(char *addr, size_t len,
462 const char *name_hint);
463
464/**
465 * Return non-zero when addr names a reusable listener-style IPC endpoint,
466 * as opposed to a single inherited connected endpoint.
467 */
469
470/**
471 * Connect using the PKG_ADDR env var (child side).
472 */
475
476/**
477 * Wrap an already-open fd pair into a pkg_conn.
478 */
479PKG_EXPORT extern struct pkg_conn *pkg_adopt_fds(int rfd, int wfd,
480 const struct pkg_switch *switchp,
482
483/**
484 * Wrap stdin(0)/stdout(1) as a pkg connection (inetd/pipe mode).
485 */
488
489/**
490 * Move the connection's fds above min_fd.
491 * Returns 0 on success, -1 on error.
492 */
494
495
496/****************************
497 * Listener API *
498 ****************************/
499
500struct pkg_listener;
502
504 const char *iface_or_null,
505 int backlog,
508 const struct pkg_switch *switchp,
510 int nonblocking);
514
515
516/****************************
517 * Multiplexer API *
518 ****************************/
519
520struct pkg_mux;
521typedef struct pkg_mux pkg_mux_t;
522
525PKG_EXPORT extern int pkg_mux_add_conn(pkg_mux_t *m, const struct pkg_conn *pc);
530PKG_EXPORT extern int pkg_mux_is_ready_conn(const pkg_mux_t *m, const struct pkg_conn *pc);
532PKG_EXPORT extern int pkg_mux_is_ready_fd(const pkg_mux_t *m, int fd);
533
534
535/****************************
536 * Data conversion routines *
537 ****************************/
538
539/**
540 * Get a 16-bit short from a char[2] array
541 */
542PKG_EXPORT extern unsigned short pkg_gshort(char *buf);
543
544/**
545 * Get a 32-bit long from a char[4] array
546 */
547PKG_EXPORT extern unsigned long pkg_glong(char *buf);
548
549/**
550 * Put a 16-bit short into a char[2] array
551 */
552PKG_EXPORT extern char *pkg_pshort(char *buf, unsigned short s);
553
554/**
555 * Put a 32-bit long into a char[4] array
556 */
557PKG_EXPORT extern char *pkg_plong(char *buf, unsigned long l);
558
559/**
560 * returns a human-readable string describing this version of the
561 * LIBPKG library.
562 */
563PKG_EXPORT extern const char *pkg_version(void);
564
565#ifdef __cplusplus
566}
567#endif
568
569#endif /* PKG_H */
570
571/** @} */
572/*
573 * Local Variables:
574 * mode: C
575 * tab-width: 8
576 * indent-tabs-mode: t
577 * c-file-style: "stroustrup"
578 * End:
579 * ex: shiftwidth=4 tabstop=8
580 */
Definition dvec.h:74
Header file for the BRL-CAD common definitions.
int pkg_mux_is_ready_conn(const pkg_mux_t *m, const struct pkg_conn *pc)
const char * pkg_child_addr(struct pkg_conn *pc)
int pkg_waitfor(int type, char *buf, size_t len, struct pkg_conn *pc)
int pkg_get_read_fd(const struct pkg_conn *pc)
int pkg_send(int type, const char *buf, size_t len, struct pkg_conn *pc)
pkg_mux_t * pkg_mux_create(void)
char * pkg_pshort(char *buf, unsigned short s)
void pkg_mux_remove_fd(pkg_mux_t *m, int fd)
int pkg_addr_is_ipc_listener(const char *addr)
int pkg_flush(struct pkg_conn *pc)
void(* pkg_errlog)(const char *msg)
Definition pkg.h:57
unsigned long pkg_glong(char *buf)
void pkg_mux_destroy(pkg_mux_t *m)
int pkg_stream(int type, const char *buf, size_t len, struct pkg_conn *pc)
pkg_listener_t * pkg_listen(const char *service, const char *iface_or_null, int backlog, pkg_errlog errlog)
int pkg_mux_add_conn(pkg_mux_t *m, const struct pkg_conn *pc)
int pkg_pair(struct pkg_conn **parent_end, struct pkg_conn **child_end, const struct pkg_switch *switchp, pkg_errlog errlog)
#define PKG_STREAMLEN
Definition pkg.h:80
int pkg_mux_add_fd(pkg_mux_t *m, int fd, int is_socket)
struct pkg_conn * pkg_adopt_stdio(const struct pkg_switch *switchp, pkg_errlog errlog)
int pkg_set_recv_buffer(struct pkg_conn *pc, size_t bytes)
int pkg_mux_add_listener(pkg_mux_t *m, const pkg_listener_t *L)
int pkg_block(struct pkg_conn *pc)
int pkg_pair_prefer(struct pkg_conn **parent_end, struct pkg_conn **child_end, const struct pkg_switch *switchp, pkg_errlog errlog, pkg_transport_t preferred)
void(* pkg_callback)(struct pkg_conn *, char *)
Definition pkg.h:56
int pkg_get_listener_fd(const pkg_listener_t *L)
struct pkg_conn * pkg_open(const char *host, const char *service, const char *protocol, const char *username, const char *passwd, const struct pkg_switch *switchp, pkg_errlog errlog)
int pkg_2send(int type, const char *buf1, size_t len1, const char *buf2, size_t len2, struct pkg_conn *pc)
void pkg_close(struct pkg_conn *pc)
int pkg_get_listener_port(const pkg_listener_t *L)
int pkg_ipc_addr(char *addr, size_t len, const char *name_hint)
struct pkg_conn * pkg_adopt_socket(int fd, const struct pkg_switch *switchp, pkg_errlog errlog)
struct pkg_conn * pkg_connect_env(const struct pkg_switch *switchp, pkg_errlog errlog)
struct pkg_conn * pkg_accept(pkg_listener_t *L, const struct pkg_switch *switchp, pkg_errlog errlog, int nonblocking)
int pkg_set_tls(struct pkg_conn *pc, void *tls_ctx, ptrdiff_t(*tls_read)(void *ctx, void *buf, size_t n), ptrdiff_t(*tls_write)(void *ctx, const void *buf, size_t n), void(*tls_free)(void *ctx))
void pkg_listener_close(pkg_listener_t *L)
const char * pkg_child_addr_env(struct pkg_conn *pc)
int pkg_set_nodelay(struct pkg_conn *pc, int on)
char * pkg_bwaitfor(int type, struct pkg_conn *pc)
int pkg_process(struct pkg_conn *)
int pkg_suckin(struct pkg_conn *)
int pkg_mux_is_ready_fd(const pkg_mux_t *m, int fd)
int pkg_move_high_fd(struct pkg_conn *pc, int min_fd)
pkg_transport_t
Definition pkg.h:390
struct pkg_conn * pkg_connect_addr(const char *addr, const struct pkg_switch *switchp, pkg_errlog errlog)
int pkg_mux_is_ready_listener(const pkg_mux_t *m, const pkg_listener_t *L)
int pkg_get_write_fd(const struct pkg_conn *pc)
struct pkg_conn * pkg_adopt_fds(int rfd, int wfd, const struct pkg_switch *switchp, pkg_errlog errlog)
int pkg_mux_wait(pkg_mux_t *m, int timeout_ms)
int pkg_set_send_buffer(struct pkg_conn *pc, size_t bytes)
unsigned short pkg_gshort(char *buf)
int pkg_is_stdio_mode(const struct pkg_conn *pc)
char * pkg_plong(char *buf, unsigned long l)
const char * pkg_version(void)
@ PKG_TRANSPORT_TCP
TCP loopback transport.
Definition pkg.h:394
@ PKG_TRANSPORT_SOCKET
POSIX socketpair transport.
Definition pkg.h:393
@ PKG_TRANSPORT_AUTO
Use default probe order.
Definition pkg.h:391
@ PKG_TRANSPORT_PIPE
Anonymous pipe transport.
Definition pkg.h:392
Definition pkg.h:81
int pkc_tx_kind
transport kind: 0=socket/TCP, 1=pipe pair
Definition pkg.h:132
int pkc_fd
TCP connection fd.
Definition pkg.h:82
void * pkc_tls_ctx
opaque TLS state (e.g. SSL *)
Definition pkg.h:126
struct pkg_header pkc_hdr
hdr of cur msg
Definition pkg.h:88
pkg_errlog pkc_errlog
Error message logger.
Definition pkg.h:87
int pkc_incur
current pos in inbuf
Definition pkg.h:98
int pkc_strpos
index into stream buffer
Definition pkg.h:95
int pkc_inend
first unused pos in inbuf
Definition pkg.h:99
int pkc_left
# bytes pkg_get expects
Definition pkg.h:102
int pkc_in_fd
input fd for split-fd (pipe) transports
Definition pkg.h:83
char * pkc_inbuf
input stream buffer
Definition pkg.h:97
char pkc_addr_env[160]
PKG_ADDR=... env string for child spawn (future phases)
Definition pkg.h:131
void * pkc_user_data
User defined pointer to data for the current pkg_type.
Definition pkg.h:91
int pkc_listen_fd
listening socket fd for lazy-accept (TCP, future phases)
Definition pkg.h:133
ptrdiff_t(* pkc_tls_write)(void *ctx, const void *buf, size_t n)
TLS write callback; NULL = use raw fd.
Definition pkg.h:128
unsigned int pkc_magic
for validating pointers
Definition pkg.h:94
int pkc_out_fd
output fd for split-fd (pipe) transports
Definition pkg.h:84
size_t pkc_len
pkg_len, in host order
Definition pkg.h:89
void(* pkc_tls_free)(void *ctx)
called by pkg_close() to free TLS state
Definition pkg.h:129
const struct pkg_switch * pkc_switch
Array of message handlers.
Definition pkg.h:86
ptrdiff_t(* pkc_tls_read)(void *ctx, void *buf, size_t n)
TLS read callback; NULL = use raw fd.
Definition pkg.h:127
char * pkc_curpos
current position in pkg_buf
Definition pkg.h:105
void * pkc_server_data
used to hold server data for callbacks
Definition pkg.h:106
unsigned short pkc_type
pkg_type, in host order
Definition pkg.h:90
char pkc_addr[128]
transport address string (populated by future phases)
Definition pkg.h:130
char pkc_stream[PKG_STREAMLEN]
output stream
Definition pkg.h:93
int pkc_inlen
length of pkc_inbuf
Definition pkg.h:100
char * pkc_buf
start of dynamic buf
Definition pkg.h:104
unsigned char pkh_type[2]
Message Type.
Definition pkg.h:76
unsigned char pkh_len[4]
Byte count of remainder.
Definition pkg.h:77
unsigned char pkh_magic[2]
Ident.
Definition pkg.h:75
unsigned short pks_type
Type code.
Definition pkg.h:60
void * pks_user_data
User defined pointer to data.
Definition pkg.h:63
const char * pks_title
Description of message type.
Definition pkg.h:62
pkg_callback pks_handler
Message Handler.
Definition pkg.h:61