HIPC  0.5
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
posix_clientutils.c
Go to the documentation of this file.
1 #include <errno.h>
2 
3 #include <hipc/posix/ioutils.h>
5 
16 enum HIPC_errno hipcPosixReadMsg(void *arg, hipc_msg msg)
17 {
18  int const *const fd_p = arg;
19  ssize_t i;
20 
21  errno = 0;
22  i = hipcPosixReadExactly(*fd_p, msg, HIPC_MSGHDR_SIZE);
23  if (0 >= i) {
24  return HIPC_ERR_IO_READ;
25  }
26  if (0 < hipcMsgBdySize(msg)) {
27  i = hipcPosixReadExactly(*fd_p, &msg[HIPC_MSGHDR_SIZE],
28  hipcMsgBdySize(msg));
29  if (0 >= i) {
30  return HIPC_ERR_IO_READ;
31  }
32  }
33 
34  return HIPC_SUCCESS;
35 }
36 
47 enum HIPC_errno hipcPosixWriteMsg(void *arg, const hipc_msg msg)
48 {
49  int const *const fd_p = arg;
50 
51  errno = 0;
52  if (-1 == hipcPosixWriteExactly(*fd_p, msg, hipcMsgTotalSize(msg))) {
53  return HIPC_ERR_IO_WRITE;
54  }
55 
56  return HIPC_SUCCESS;
57 }
unsigned char hipc_msg[HIPC_MSG_ALLOCSIZE]
Definition: msg.h:8
size_t hipcMsgTotalSize(const hipc_msg msg)
Returns total size of a HIPC message, which is the header size plus the body size.
Definition: msg.c:9
ssize_t hipcPosixReadExactly(const int fd, void *buf, const size_t count)
Read count bytes from fd by using read(2).
Definition: posix_ioutils.c:41
HIPC_errno
Definition: hipc.h:4
enum HIPC_errno hipcPosixReadMsg(void *arg, hipc_msg msg)
Read a HIPC message from fd.
ssize_t hipcPosixWriteExactly(const int fd, void const *buf, const size_t count)
Writes count bytes to fd by using write(2).
Definition: posix_ioutils.c:71
unsigned char hipcMsgBdySize(const hipc_msg msg)
Returns body size of a HIPC message.
Definition: msg.c:20
enum HIPC_errno hipcPosixWriteMsg(void *arg, const hipc_msg msg)
Write a HIPC message to fd.