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