XROAD
xroad_base_writer.h
Go to the documentation of this file.
1 
12 #pragma once
13 
14 #include <sys/uio.h>
15 #include <stdbool.h>
17 
18 #ifdef __cplusplus
19 extern "C"
20 {
21 #endif
22 
23 #ifndef XROAD_WRITER_IMPL
24 # define XROAD_WEAK __attribute__((weak)) // Use weak linkage for functions that may be overridden by implementations.
25 #else
26 # define XROAD_WEAK // No weak linkage for functions that are not overridden by implementations.
27 #endif
28 
30 typedef struct xroad_base_writer_s xroad_base_writer_t;
31 
33 typedef void (*xroad_writer_on_done_t)(xroad_context_t user_data, size_t bytes_written, xroad_errno_t err_code);
34 
36 XROAD_WEAK ssize_t xroad_writer_writev(xroad_base_writer_t* writer, struct iovec* iov, int iovcnt,
37  xroad_writer_on_done_t on_done, xroad_context_t user_data);
38 
40 XROAD_WEAK xroad_errno_t xroad_writer_rotate(xroad_base_writer_t* writer, bool force, int flags);
41 
43 XROAD_WEAK xroad_errno_t xroad_writer_sync(xroad_base_writer_t* writer, uint32_t flags);
44 
45 enum { xroad_writer_nofd = -1, xroad_writer_no_fd_available = -2 };
46 
50 XROAD_WEAK int xroad_writer_get_fd(xroad_base_writer_t* writer);
51 
53 XROAD_WEAK void xroad_writer_destroy(xroad_base_writer_t* writer);
54 
55 #define __xroad_writer_dtor__ __dtor__(xroad_writer_destructor)
56 
57 //--------------------------------------------------------------------------------------------------------------------//
58 inline void xroad_writer_destructor(xroad_base_writer_t** w)
59 {
60  if (*w)
61  {
63  }
64 }
65 
66 #ifdef __cplusplus
67 }
68 #endif
Union of values for transparently passing to callbacks instead of void*
Definition: xroad_common_types.h:98
void(* xroad_writer_on_done_t)(xroad_context_t user_data, size_t bytes_written, xroad_errno_t err_code)
Callback function type for handling completion of write operations.
Definition: xroad_base_writer.h:33
XROAD_WEAK xroad_errno_t xroad_writer_rotate(xroad_base_writer_t *writer, bool force, int flags)
Rotate the file associated with the writer. Flags is reserved.
XROAD_WEAK void xroad_writer_destroy(xroad_base_writer_t *writer)
Destroy the writer object.
XROAD_WEAK xroad_errno_t xroad_writer_sync(xroad_base_writer_t *writer, uint32_t flags)
Synchronize the recent writer operation(s). flags is reserved.
XROAD_WEAK int xroad_writer_get_fd(xroad_base_writer_t *writer)
struct xroad_base_writer_s xroad_base_writer_t
Base structure for a file writer. Implementations should extend this structure.
Definition: xroad_base_writer.h:30
XROAD_WEAK ssize_t xroad_writer_writev(xroad_base_writer_t *writer, struct iovec *iov, int iovcnt, xroad_writer_on_done_t on_done, xroad_context_t user_data)
Write data to a file using the file writer. Returns number of bytes written or negative error code (x...