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