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