[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 |
|
---|
[2aa15d4] | 40 | #include <ipc/net.h>
|
---|
[21580dd] | 41 |
|
---|
[88e127ee] | 42 | /** Socket client messages. */
|
---|
| 43 | typedef enum {
|
---|
| 44 | /** Creates a new socket. @see socket() */
|
---|
[21580dd] | 45 | NET_SOCKET = NET_SOCKET_FIRST,
|
---|
[88e127ee] | 46 | /** Binds the socket. @see bind() */
|
---|
[21580dd] | 47 | NET_SOCKET_BIND,
|
---|
[88e127ee] | 48 | /** Creates a new socket. @see socket() */
|
---|
[21580dd] | 49 | NET_SOCKET_LISTEN,
|
---|
[88e127ee] | 50 | /** Accepts an incomming connection. @see accept() */
|
---|
[21580dd] | 51 | NET_SOCKET_ACCEPT,
|
---|
[88e127ee] | 52 | /** Connects the socket. @see connect() */
|
---|
[21580dd] | 53 | NET_SOCKET_CONNECT,
|
---|
[88e127ee] | 54 | /** Closes the socket. @see closesocket() */
|
---|
[21580dd] | 55 | NET_SOCKET_CLOSE,
|
---|
[88e127ee] | 56 | /** Sends data via the stream socket. @see send() */
|
---|
[21580dd] | 57 | NET_SOCKET_SEND,
|
---|
[88e127ee] | 58 | /** Sends data via the datagram socket. @see sendto() */
|
---|
[21580dd] | 59 | NET_SOCKET_SENDTO,
|
---|
[88e127ee] | 60 | /** Receives data from the stream socket. @see socket() */
|
---|
[21580dd] | 61 | NET_SOCKET_RECV,
|
---|
[88e127ee] | 62 | /** Receives data from the datagram socket. @see socket() */
|
---|
[21580dd] | 63 | NET_SOCKET_RECVFROM,
|
---|
[88e127ee] | 64 | /** Gets the socket option. @see getsockopt() */
|
---|
[21580dd] | 65 | NET_SOCKET_GETSOCKOPT,
|
---|
[88e127ee] | 66 | /** Sets the socket option. @see setsockopt() */
|
---|
[21580dd] | 67 | NET_SOCKET_SETSOCKOPT,
|
---|
[88e127ee] | 68 | /** New socket for acceptence notification message. */
|
---|
[21580dd] | 69 | NET_SOCKET_ACCEPTED,
|
---|
[88e127ee] | 70 | /** New data received notification message. */
|
---|
[21580dd] | 71 | NET_SOCKET_RECEIVED,
|
---|
[88e127ee] | 72 | /** New socket data fragment size notification message. */
|
---|
[21580dd] | 73 | NET_SOCKET_DATA_FRAGMENT_SIZE
|
---|
| 74 | } socket_messages;
|
---|
| 75 |
|
---|
| 76 | /** @name Socket specific message parameters definitions
|
---|
| 77 | */
|
---|
| 78 | /*@{*/
|
---|
| 79 |
|
---|
| 80 | /** Sets the socket identifier in the message answer.
|
---|
[88e127ee] | 81 | * @param[out] answer The message answer structure.
|
---|
[21580dd] | 82 | */
|
---|
[e417b96] | 83 | #define SOCKET_SET_SOCKET_ID(answer, value) \
|
---|
[88e127ee] | 84 | do { \
|
---|
[96b02eb9] | 85 | sysarg_t argument = (sysarg_t) (value); \
|
---|
[88e127ee] | 86 | IPC_SET_ARG1(answer, argument); \
|
---|
| 87 | } while (0)
|
---|
[21580dd] | 88 |
|
---|
| 89 | /** Returns the socket identifier message parameter.
|
---|
[88e127ee] | 90 | * @param[in] call The message call structure.
|
---|
[21580dd] | 91 | */
|
---|
[e417b96] | 92 | #define SOCKET_GET_SOCKET_ID(call) \
|
---|
[88e127ee] | 93 | ({ \
|
---|
| 94 | int socket_id = (int) IPC_GET_ARG1(call); \
|
---|
| 95 | socket_id; \
|
---|
| 96 | })
|
---|
[21580dd] | 97 |
|
---|
| 98 | /** Sets the read data length in the message answer.
|
---|
[88e127ee] | 99 | * @param[out] answer The message answer structure.
|
---|
[21580dd] | 100 | */
|
---|
[e417b96] | 101 | #define SOCKET_SET_READ_DATA_LENGTH(answer, value) \
|
---|
[88e127ee] | 102 | do { \
|
---|
[96b02eb9] | 103 | sysarg_t argument = (sysarg_t) (value); \
|
---|
[88e127ee] | 104 | IPC_SET_ARG1(answer, argument); \
|
---|
| 105 | } while (0)
|
---|
[21580dd] | 106 |
|
---|
| 107 | /** Returns the read data length message parameter.
|
---|
[88e127ee] | 108 | * @param[in] call The message call structure.
|
---|
[21580dd] | 109 | */
|
---|
[e417b96] | 110 | #define SOCKET_GET_READ_DATA_LENGTH(call) \
|
---|
[88e127ee] | 111 | ({ \
|
---|
| 112 | int data_length = (int) IPC_GET_ARG1(call); \
|
---|
| 113 | data_length; \
|
---|
| 114 | })
|
---|
[21580dd] | 115 |
|
---|
| 116 | /** Returns the backlog message parameter.
|
---|
[88e127ee] | 117 | * @param[in] call The message call structure.
|
---|
[21580dd] | 118 | */
|
---|
[e417b96] | 119 | #define SOCKET_GET_BACKLOG(call) \
|
---|
[88e127ee] | 120 | ({ \
|
---|
| 121 | int backlog = (int) IPC_GET_ARG2(call); \
|
---|
| 122 | backlog; \
|
---|
| 123 | })
|
---|
[21580dd] | 124 |
|
---|
| 125 | /** Returns the option level message parameter.
|
---|
[88e127ee] | 126 | * @param[in] call The message call structure.
|
---|
[21580dd] | 127 | */
|
---|
[e417b96] | 128 | #define SOCKET_GET_OPT_LEVEL(call) \
|
---|
[88e127ee] | 129 | ({ \
|
---|
| 130 | int opt_level = (int) IPC_GET_ARG2(call); \
|
---|
| 131 | opt_level; \
|
---|
| 132 | })
|
---|
[21580dd] | 133 |
|
---|
| 134 | /** Returns the data fragment size message parameter.
|
---|
[88e127ee] | 135 | * @param[in] call The message call structure.
|
---|
[21580dd] | 136 | */
|
---|
[e417b96] | 137 | #define SOCKET_GET_DATA_FRAGMENT_SIZE(call) \
|
---|
[88e127ee] | 138 | ({ \
|
---|
| 139 | size_t size = (size_t) IPC_GET_ARG2(call); \
|
---|
| 140 | size; \
|
---|
| 141 | })
|
---|
[21580dd] | 142 |
|
---|
| 143 | /** Sets the data fragment size in the message answer.
|
---|
[88e127ee] | 144 | * @param[out] answer The message answer structure.
|
---|
[21580dd] | 145 | */
|
---|
[e417b96] | 146 | #define SOCKET_SET_DATA_FRAGMENT_SIZE(answer, value) \
|
---|
[88e127ee] | 147 | do { \
|
---|
[96b02eb9] | 148 | sysarg_t argument = (sysarg_t) (value); \
|
---|
[88e127ee] | 149 | IPC_SET_ARG2(answer, argument); \
|
---|
| 150 | } while (0)
|
---|
[21580dd] | 151 |
|
---|
[ede63e4] | 152 | /** Sets the address length in the message answer.
|
---|
[88e127ee] | 153 | * @param[out] answer The message answer structure.
|
---|
[ede63e4] | 154 | */
|
---|
[e417b96] | 155 | #define SOCKET_SET_ADDRESS_LENGTH(answer, value) \
|
---|
[88e127ee] | 156 | do { \
|
---|
[96b02eb9] | 157 | sysarg_t argument = (sysarg_t) (value); \
|
---|
[88e127ee] | 158 | IPC_SET_ARG3(answer, argument);\
|
---|
| 159 | } while (0)
|
---|
[ede63e4] | 160 |
|
---|
| 161 | /** Returns the address length message parameter.
|
---|
[88e127ee] | 162 | * @param[in] call The message call structure.
|
---|
[ede63e4] | 163 | */
|
---|
[e417b96] | 164 | #define SOCKET_GET_ADDRESS_LENGTH(call) \
|
---|
[88e127ee] | 165 | ({ \
|
---|
| 166 | socklen_t address_length = (socklen_t) IPC_GET_ARG3(call); \
|
---|
| 167 | address_length; \
|
---|
| 168 | })
|
---|
[ede63e4] | 169 |
|
---|
[21580dd] | 170 | /** Sets the header size in the message answer.
|
---|
[88e127ee] | 171 | * @param[out] answer The message answer structure.
|
---|
[21580dd] | 172 | */
|
---|
[e417b96] | 173 | #define SOCKET_SET_HEADER_SIZE(answer, value) \
|
---|
[88e127ee] | 174 | do { \
|
---|
[96b02eb9] | 175 | sysarg_t argument = (sysarg_t) (value); \
|
---|
[88e127ee] | 176 | IPC_SET_ARG3(answer, argument); \
|
---|
| 177 | } while (0)
|
---|
[21580dd] | 178 |
|
---|
| 179 | /** Returns the header size message parameter.
|
---|
[88e127ee] | 180 | * @param[in] call The message call structure.
|
---|
[21580dd] | 181 | */
|
---|
[e417b96] | 182 | #define SOCKET_GET_HEADER_SIZE(call) \
|
---|
[88e127ee] | 183 | ({ \
|
---|
| 184 | size_t size = (size_t) IPC_GET_ARG3(call); \
|
---|
| 185 | size; \
|
---|
| 186 | })
|
---|
[21580dd] | 187 |
|
---|
| 188 | /** Returns the flags message parameter.
|
---|
[88e127ee] | 189 | * @param[in] call The message call structure.
|
---|
[21580dd] | 190 | */
|
---|
[e417b96] | 191 | #define SOCKET_GET_FLAGS(call) \
|
---|
[88e127ee] | 192 | ({ \
|
---|
| 193 | int flags = (int) IPC_GET_ARG4(call); \
|
---|
| 194 | flags; \
|
---|
| 195 | })
|
---|
[21580dd] | 196 |
|
---|
| 197 | /** Returns the option name message parameter.
|
---|
[88e127ee] | 198 | * @param[in] call The message call structure.
|
---|
[21580dd] | 199 | */
|
---|
[e417b96] | 200 | #define SOCKET_GET_OPT_NAME(call) \
|
---|
[88e127ee] | 201 | ({ \
|
---|
| 202 | int opt_name = (int) IPC_GET_ARG4(call); \
|
---|
| 203 | opt_name; \
|
---|
| 204 | })
|
---|
[21580dd] | 205 |
|
---|
| 206 | /** Returns the data fragments message parameter.
|
---|
[88e127ee] | 207 | * @param[in] call The message call structure.
|
---|
[21580dd] | 208 | */
|
---|
[e417b96] | 209 | #define SOCKET_GET_DATA_FRAGMENTS(call) \
|
---|
[88e127ee] | 210 | ({ \
|
---|
| 211 | int fragments = (int) IPC_GET_ARG5(call); \
|
---|
| 212 | fragments; \
|
---|
| 213 | })
|
---|
[21580dd] | 214 |
|
---|
| 215 | /** Returns the new socket identifier message parameter.
|
---|
[88e127ee] | 216 | * @param[in] call The message call structure.
|
---|
[21580dd] | 217 | */
|
---|
[e417b96] | 218 | #define SOCKET_GET_NEW_SOCKET_ID(call) \
|
---|
[88e127ee] | 219 | ({ \
|
---|
| 220 | int socket_id = (int) IPC_GET_ARG5(call); \
|
---|
| 221 | socket_id; \
|
---|
| 222 | })
|
---|
[21580dd] | 223 |
|
---|
| 224 | /*@}*/
|
---|
| 225 |
|
---|
| 226 | #endif
|
---|
| 227 |
|
---|
| 228 | /** @}
|
---|
| 229 | */
|
---|