Code

Merged branch 'master' of git://git.tokkee.org/sysdb.
[sysdb.git] / src / include / client / sock.h
1 /*
2  * SysDB - src/include/client/sock.h
3  * Copyright (C) 2013 Sebastian 'tokkee' Harl <sh@tokkee.org>
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
19  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
28 #ifndef SDB_CLIENT_SOCK_H
29 #define SDB_CLIENT_SOCK_H 1
31 #include "core/object.h"
32 #include "core/data.h"
34 #include "frontend/proto.h"
36 #include "utils/strbuf.h"
38 #include <sys/socket.h>
40 #include <stddef.h>
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
46 struct sdb_client;
47 typedef struct sdb_client sdb_client_t;
49 /*
50  * sdb_client_create:
51  * Allocates and initializes a client object to connect to the specified
52  * address.
53  *
54  * Returns:
55  *  - a new client object on success
56  *  - NULL in case of an error
57  */
58 sdb_client_t *
59 sdb_client_create(const char *address);
61 /*
62  * sdb_client_destroy:
63  * Destroyes the client connection and deallocates the client object.
64  */
65 void
66 sdb_client_destroy(sdb_client_t *client);
68 /*
69  * sdb_client_connect:
70  * Connect to the client's address using the specified username.
71  *
72  * Returns:
73  *  - 0 on success
74  *  - a negative value else
75  */
76 int
77 sdb_client_connect(sdb_client_t *client, const char *username);
79 /*
80  * sdb_client_close:
81  * Close the client connection.
82  */
83 void
84 sdb_client_close(sdb_client_t *client);
86 /*
87  * sdb_client_send:
88  * Send the specified command and accompanying data to through the client
89  * connection.
90  *
91  * Returns:
92  *  - 0 on success
93  *  - a negative value else.
94  */
95 ssize_t
96 sdb_client_send(sdb_client_t *client,
97                 uint32_t cmd, uint32_t data_len, const char *data);
99 /*
100  * sdb_client_recv:
101  * Receive data from the connection. All data is written to the specified
102  * buffer. If specified, the returned status code is written to the memory
103  * location pointed to by 'code'. In case of an error or an incomplete
104  * command, the status code is set to UINT32_MAX. The returned data does not
105  * include the status code and message len as received from the remote side
106  * but only the data associated with the message.
107  *
108  * Returns:
109  *  - the number of bytes read
110  *    (may be zero if the message did not include any data)
111  *  - a negative value on error
112  */
113 ssize_t
114 sdb_client_recv(sdb_client_t *client,
115                 uint32_t *code, sdb_strbuf_t *buf);
117 #ifdef __cplusplus
118 } /* extern "C" */
119 #endif
121 #endif /* ! SDB_CLIENT_SOCK_H */
123 /* vim: set tw=78 sw=4 ts=4 noexpandtab : */