[21580dd] | 1 | /*
|
---|
| 2 | * Copyright (c) 2009 Lukas Mejdrech
|
---|
| 3 | * All rights reserved.
|
---|
| 4 | *
|
---|
| 5 | * Redistribution and use in source and binary forms, with or without
|
---|
| 6 | * modification, are permitted provided that the following conditions
|
---|
| 7 | * are met:
|
---|
| 8 | *
|
---|
| 9 | * - Redistributions of source code must retain the above copyright
|
---|
| 10 | * notice, this list of conditions and the following disclaimer.
|
---|
| 11 | * - 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 | * - The name of the author may not be used to endorse or promote products
|
---|
| 15 | * derived from this software without specific prior written permission.
|
---|
| 16 | *
|
---|
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
| 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
| 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
| 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
| 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
| 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
| 27 | */
|
---|
| 28 |
|
---|
[88e127ee] | 29 | /** @addtogroup libc
|
---|
| 30 | * @{
|
---|
[21580dd] | 31 | */
|
---|
| 32 |
|
---|
| 33 | /** @file
|
---|
[88e127ee] | 34 | * Socket messages.
|
---|
[21580dd] | 35 | */
|
---|
| 36 |
|
---|
[88e127ee] | 37 | #ifndef LIBC_SOCKET_MESSAGES_H_
|
---|
| 38 | #define LIBC_SOCKET_MESSAGES_H_
|
---|
[21580dd] | 39 |
|
---|
| 40 | #include <ipc/ipc.h>
|
---|
[2aa15d4] | 41 | #include <ipc/net.h>
|
---|
[21580dd] | 42 |
|
---|
[88e127ee] | 43 | /** Socket client messages. */
|
---|
| 44 | typedef enum {
|
---|
| 45 | /** Creates a new socket. @see socket() */
|
---|
[21580dd] | 46 | NET_SOCKET = NET_SOCKET_FIRST,
|
---|
[88e127ee] | 47 | /** Binds the socket. @see bind() */
|
---|
[21580dd] | 48 | NET_SOCKET_BIND,
|
---|
[88e127ee] | 49 | /** Creates a new socket. @see socket() */
|
---|
[21580dd] | 50 | NET_SOCKET_LISTEN,
|
---|
[88e127ee] | 51 | /** Accepts an incomming connection. @see accept() */
|
---|
[21580dd] | 52 | NET_SOCKET_ACCEPT,
|
---|
[88e127ee] | 53 | /** Connects the socket. @see connect() */
|
---|
[21580dd] | 54 | NET_SOCKET_CONNECT,
|
---|
[88e127ee] | 55 | /** Closes the socket. @see closesocket() */
|
---|
[21580dd] | 56 | NET_SOCKET_CLOSE,
|
---|
[88e127ee] | 57 | /** Sends data via the stream socket. @see send() */
|
---|
[21580dd] | 58 | NET_SOCKET_SEND,
|
---|
[88e127ee] | 59 | /** Sends data via the datagram socket. @see sendto() */
|
---|
[21580dd] | 60 | NET_SOCKET_SENDTO,
|
---|
[88e127ee] | 61 | /** Receives data from the stream socket. @see socket() */
|
---|
[21580dd] | 62 | NET_SOCKET_RECV,
|
---|
[88e127ee] | 63 | /** Receives data from the datagram socket. @see socket() */
|
---|
[21580dd] | 64 | NET_SOCKET_RECVFROM,
|
---|
[88e127ee] | 65 | /** Gets the socket option. @see getsockopt() */
|
---|
[21580dd] | 66 | NET_SOCKET_GETSOCKOPT,
|
---|
[88e127ee] | 67 | /** Sets the socket option. @see setsockopt() */
|
---|
[21580dd] | 68 | NET_SOCKET_SETSOCKOPT,
|
---|
[88e127ee] | 69 | /** New socket for acceptence notification message. */
|
---|
[21580dd] | 70 | NET_SOCKET_ACCEPTED,
|
---|
[88e127ee] | 71 | /** New data received notification message. */
|
---|
[21580dd] | 72 | NET_SOCKET_RECEIVED,
|
---|
[88e127ee] | 73 | /** New socket data fragment size notification message. */
|
---|
[21580dd] | 74 | NET_SOCKET_DATA_FRAGMENT_SIZE
|
---|
| 75 | } socket_messages;
|
---|
| 76 |
|
---|
| 77 | /** @name Socket specific message parameters definitions
|
---|
| 78 | */
|
---|
| 79 | /*@{*/
|
---|
| 80 |
|
---|
| 81 | /** Sets the socket identifier in the message answer.
|
---|
[88e127ee] | 82 | * @param[out] answer The message answer structure.
|
---|
[21580dd] | 83 | */
|
---|
[e417b96] | 84 | #define SOCKET_SET_SOCKET_ID(answer, value) \
|
---|
[88e127ee] | 85 | do { \
|
---|
| 86 | ipcarg_t argument = (ipcarg_t) (value); \
|
---|
| 87 | IPC_SET_ARG1(answer, argument); \
|
---|
| 88 | } while (0)
|
---|
[21580dd] | 89 |
|
---|
| 90 | /** Returns the socket identifier message parameter.
|
---|
[88e127ee] | 91 | * @param[in] call The message call structure.
|
---|
[21580dd] | 92 | */
|
---|
[e417b96] | 93 | #define SOCKET_GET_SOCKET_ID(call) \
|
---|
[88e127ee] | 94 | ({ \
|
---|
| 95 | int socket_id = (int) IPC_GET_ARG1(call); \
|
---|
| 96 | socket_id; \
|
---|
| 97 | })
|
---|
[21580dd] | 98 |
|
---|
| 99 | /** Sets the read data length in the message answer.
|
---|
[88e127ee] | 100 | * @param[out] answer The message answer structure.
|
---|
[21580dd] | 101 | */
|
---|
[e417b96] | 102 | #define SOCKET_SET_READ_DATA_LENGTH(answer, value) \
|
---|
[88e127ee] | 103 | do { \
|
---|
| 104 | ipcarg_t argument = (ipcarg_t) (value); \
|
---|
| 105 | IPC_SET_ARG1(answer, argument); \
|
---|
| 106 | } while (0)
|
---|
[21580dd] | 107 |
|
---|
| 108 | /** Returns the read data length message parameter.
|
---|
[88e127ee] | 109 | * @param[in] call The message call structure.
|
---|
[21580dd] | 110 | */
|
---|
[e417b96] | 111 | #define SOCKET_GET_READ_DATA_LENGTH(call) \
|
---|
[88e127ee] | 112 | ({ \
|
---|
| 113 | int data_length = (int) IPC_GET_ARG1(call); \
|
---|
| 114 | data_length; \
|
---|
| 115 | })
|
---|
[21580dd] | 116 |
|
---|
| 117 | /** Returns the backlog message parameter.
|
---|
[88e127ee] | 118 | * @param[in] call The message call structure.
|
---|
[21580dd] | 119 | */
|
---|
[e417b96] | 120 | #define SOCKET_GET_BACKLOG(call) \
|
---|
[88e127ee] | 121 | ({ \
|
---|
| 122 | int backlog = (int) IPC_GET_ARG2(call); \
|
---|
| 123 | backlog; \
|
---|
| 124 | })
|
---|
[21580dd] | 125 |
|
---|
| 126 | /** Returns the option level message parameter.
|
---|
[88e127ee] | 127 | * @param[in] call The message call structure.
|
---|
[21580dd] | 128 | */
|
---|
[e417b96] | 129 | #define SOCKET_GET_OPT_LEVEL(call) \
|
---|
[88e127ee] | 130 | ({ \
|
---|
| 131 | int opt_level = (int) IPC_GET_ARG2(call); \
|
---|
| 132 | opt_level; \
|
---|
| 133 | })
|
---|
[21580dd] | 134 |
|
---|
| 135 | /** Returns the data fragment size message parameter.
|
---|
[88e127ee] | 136 | * @param[in] call The message call structure.
|
---|
[21580dd] | 137 | */
|
---|
[e417b96] | 138 | #define SOCKET_GET_DATA_FRAGMENT_SIZE(call) \
|
---|
[88e127ee] | 139 | ({ \
|
---|
| 140 | size_t size = (size_t) IPC_GET_ARG2(call); \
|
---|
| 141 | size; \
|
---|
| 142 | })
|
---|
[21580dd] | 143 |
|
---|
| 144 | /** Sets the data fragment size in the message answer.
|
---|
[88e127ee] | 145 | * @param[out] answer The message answer structure.
|
---|
[21580dd] | 146 | */
|
---|
[e417b96] | 147 | #define SOCKET_SET_DATA_FRAGMENT_SIZE(answer, value) \
|
---|
[88e127ee] | 148 | do { \
|
---|
| 149 | ipcarg_t argument = (ipcarg_t) (value); \
|
---|
| 150 | IPC_SET_ARG2(answer, argument); \
|
---|
| 151 | } while (0)
|
---|
[21580dd] | 152 |
|
---|
[ede63e4] | 153 | /** Sets the address length in the message answer.
|
---|
[88e127ee] | 154 | * @param[out] answer The message answer structure.
|
---|
[ede63e4] | 155 | */
|
---|
[e417b96] | 156 | #define SOCKET_SET_ADDRESS_LENGTH(answer, value) \
|
---|
[88e127ee] | 157 | do { \
|
---|
| 158 | ipcarg_t argument = (ipcarg_t) (value); \
|
---|
| 159 | IPC_SET_ARG3(answer, argument);\
|
---|
| 160 | } while (0)
|
---|
[ede63e4] | 161 |
|
---|
| 162 | /** Returns the address length message parameter.
|
---|
[88e127ee] | 163 | * @param[in] call The message call structure.
|
---|
[ede63e4] | 164 | */
|
---|
[e417b96] | 165 | #define SOCKET_GET_ADDRESS_LENGTH(call) \
|
---|
[88e127ee] | 166 | ({ \
|
---|
| 167 | socklen_t address_length = (socklen_t) IPC_GET_ARG3(call); \
|
---|
| 168 | address_length; \
|
---|
| 169 | })
|
---|
[ede63e4] | 170 |
|
---|
[21580dd] | 171 | /** Sets the header size in the message answer.
|
---|
[88e127ee] | 172 | * @param[out] answer The message answer structure.
|
---|
[21580dd] | 173 | */
|
---|
[e417b96] | 174 | #define SOCKET_SET_HEADER_SIZE(answer, value) \
|
---|
[88e127ee] | 175 | do { \
|
---|
| 176 | ipcarg_t argument = (ipcarg_t) (value); \
|
---|
| 177 | IPC_SET_ARG3(answer, argument); \
|
---|
| 178 | } while (0)
|
---|
[21580dd] | 179 |
|
---|
| 180 | /** Returns the header size message parameter.
|
---|
[88e127ee] | 181 | * @param[in] call The message call structure.
|
---|
[21580dd] | 182 | */
|
---|
[e417b96] | 183 | #define SOCKET_GET_HEADER_SIZE(call) \
|
---|
[88e127ee] | 184 | ({ \
|
---|
| 185 | size_t size = (size_t) IPC_GET_ARG3(call); \
|
---|
| 186 | size; \
|
---|
| 187 | })
|
---|
[21580dd] | 188 |
|
---|
| 189 | /** Returns the flags message parameter.
|
---|
[88e127ee] | 190 | * @param[in] call The message call structure.
|
---|
[21580dd] | 191 | */
|
---|
[e417b96] | 192 | #define SOCKET_GET_FLAGS(call) \
|
---|
[88e127ee] | 193 | ({ \
|
---|
| 194 | int flags = (int) IPC_GET_ARG4(call); \
|
---|
| 195 | flags; \
|
---|
| 196 | })
|
---|
[21580dd] | 197 |
|
---|
| 198 | /** Returns the option name message parameter.
|
---|
[88e127ee] | 199 | * @param[in] call The message call structure.
|
---|
[21580dd] | 200 | */
|
---|
[e417b96] | 201 | #define SOCKET_GET_OPT_NAME(call) \
|
---|
[88e127ee] | 202 | ({ \
|
---|
| 203 | int opt_name = (int) IPC_GET_ARG4(call); \
|
---|
| 204 | opt_name; \
|
---|
| 205 | })
|
---|
[21580dd] | 206 |
|
---|
| 207 | /** Returns the data fragments message parameter.
|
---|
[88e127ee] | 208 | * @param[in] call The message call structure.
|
---|
[21580dd] | 209 | */
|
---|
[e417b96] | 210 | #define SOCKET_GET_DATA_FRAGMENTS(call) \
|
---|
[88e127ee] | 211 | ({ \
|
---|
| 212 | int fragments = (int) IPC_GET_ARG5(call); \
|
---|
| 213 | fragments; \
|
---|
| 214 | })
|
---|
[21580dd] | 215 |
|
---|
| 216 | /** Returns the new socket identifier message parameter.
|
---|
[88e127ee] | 217 | * @param[in] call The message call structure.
|
---|
[21580dd] | 218 | */
|
---|
[e417b96] | 219 | #define SOCKET_GET_NEW_SOCKET_ID(call) \
|
---|
[88e127ee] | 220 | ({ \
|
---|
| 221 | int socket_id = (int) IPC_GET_ARG5(call); \
|
---|
| 222 | socket_id; \
|
---|
| 223 | })
|
---|
[21580dd] | 224 |
|
---|
| 225 | /*@}*/
|
---|
| 226 |
|
---|
| 227 | #endif
|
---|
| 228 |
|
---|
| 229 | /** @}
|
---|
| 230 | */
|
---|