Changeset 4c53333 in mainline for uspace/lib/c/generic/net/socket_client.c
- Timestamp:
- 2013-07-11T08:21:10Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 64e63ce1
- Parents:
- 80445cf (diff), c8bb1633 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/net/socket_client.c
r80445cf r4c53333 44 44 #include <errno.h> 45 45 #include <task.h> 46 #include <ns.h> 46 47 #include <ipc/services.h> 47 48 #include <ipc/socket.h> 48 #include <net/modules.h>49 49 #include <net/in.h> 50 50 #include <net/socket.h> … … 87 87 /** Parent module service. */ 88 88 services_t service; 89 /** Socket family */ 90 int family; 89 91 90 92 /** … … 192 194 /** Default thread for new connections. 193 195 * 194 * @param[in] iid The initial message identifier. 195 * @param[in] icall The initial message call structure. 196 * @param[in] arg Local argument. 196 * @param[in] iid The initial message identifier. 197 * @param[in] icall The initial message call structure. 198 * @param[in] arg Local argument. 199 * 197 200 */ 198 201 static void socket_connection(ipc_callid_t iid, ipc_call_t * icall, void *arg) 199 202 { 200 ipc_callid_t callid; 201 ipc_call_t call; 202 socket_t *socket; 203 int rc; 204 205 loop: 206 callid = async_get_call(&call); 207 208 switch (IPC_GET_IMETHOD(call)) { 209 case NET_SOCKET_RECEIVED: 210 case NET_SOCKET_ACCEPTED: 211 case NET_SOCKET_DATA_FRAGMENT_SIZE: 212 fibril_rwlock_read_lock(&socket_globals.lock); 213 214 /* Find the socket */ 215 socket = sockets_find(socket_get_sockets(), 216 SOCKET_GET_SOCKET_ID(call)); 217 if (!socket) { 218 rc = ENOTSOCK; 219 fibril_rwlock_read_unlock(&socket_globals.lock); 220 break; 203 while (true) { 204 ipc_call_t call; 205 ipc_callid_t callid = async_get_call(&call); 206 207 if (!IPC_GET_IMETHOD(call)) { 208 async_answer_0(callid, 0); 209 return; 221 210 } 211 212 int rc; 222 213 223 214 switch (IPC_GET_IMETHOD(call)) { 224 215 case NET_SOCKET_RECEIVED: 225 fibril_mutex_lock(&socket->receive_lock); 226 /* Push the number of received packet fragments */ 227 rc = dyn_fifo_push(&socket->received, 228 SOCKET_GET_DATA_FRAGMENTS(call), 229 SOCKET_MAX_RECEIVED_SIZE); 230 if (rc == EOK) { 231 /* Signal the received packet */ 232 fibril_condvar_signal(&socket->receive_signal); 216 case NET_SOCKET_ACCEPTED: 217 case NET_SOCKET_DATA_FRAGMENT_SIZE: 218 fibril_rwlock_read_lock(&socket_globals.lock); 219 220 /* Find the socket */ 221 socket_t *socket = sockets_find(socket_get_sockets(), 222 SOCKET_GET_SOCKET_ID(call)); 223 if (!socket) { 224 rc = ENOTSOCK; 225 fibril_rwlock_read_unlock(&socket_globals.lock); 226 break; 233 227 } 234 fibril_mutex_unlock(&socket->receive_lock); 228 229 switch (IPC_GET_IMETHOD(call)) { 230 case NET_SOCKET_RECEIVED: 231 fibril_mutex_lock(&socket->receive_lock); 232 /* Push the number of received packet fragments */ 233 rc = dyn_fifo_push(&socket->received, 234 SOCKET_GET_DATA_FRAGMENTS(call), 235 SOCKET_MAX_RECEIVED_SIZE); 236 if (rc == EOK) { 237 /* Signal the received packet */ 238 fibril_condvar_signal(&socket->receive_signal); 239 } 240 fibril_mutex_unlock(&socket->receive_lock); 241 break; 242 243 case NET_SOCKET_ACCEPTED: 244 /* Push the new socket identifier */ 245 fibril_mutex_lock(&socket->accept_lock); 246 rc = dyn_fifo_push(&socket->accepted, 1, 247 SOCKET_MAX_ACCEPTED_SIZE); 248 if (rc == EOK) { 249 /* Signal the accepted socket */ 250 fibril_condvar_signal(&socket->accept_signal); 251 } 252 fibril_mutex_unlock(&socket->accept_lock); 253 break; 254 255 default: 256 rc = ENOTSUP; 257 } 258 259 if ((SOCKET_GET_DATA_FRAGMENT_SIZE(call) > 0) && 260 (SOCKET_GET_DATA_FRAGMENT_SIZE(call) != 261 socket->data_fragment_size)) { 262 fibril_rwlock_write_lock(&socket->sending_lock); 263 264 /* Set the data fragment size */ 265 socket->data_fragment_size = 266 SOCKET_GET_DATA_FRAGMENT_SIZE(call); 267 268 fibril_rwlock_write_unlock(&socket->sending_lock); 269 } 270 271 fibril_rwlock_read_unlock(&socket_globals.lock); 235 272 break; 236 237 case NET_SOCKET_ACCEPTED: 238 /* Push the new socket identifier */ 239 fibril_mutex_lock(&socket->accept_lock); 240 rc = dyn_fifo_push(&socket->accepted, 1, 241 SOCKET_MAX_ACCEPTED_SIZE); 242 if (rc == EOK) { 243 /* Signal the accepted socket */ 244 fibril_condvar_signal(&socket->accept_signal); 245 } 246 fibril_mutex_unlock(&socket->accept_lock); 247 break; 248 273 249 274 default: 250 275 rc = ENOTSUP; 251 276 } 252 253 if ((SOCKET_GET_DATA_FRAGMENT_SIZE(call) > 0) && 254 (SOCKET_GET_DATA_FRAGMENT_SIZE(call) != 255 socket->data_fragment_size)) { 256 fibril_rwlock_write_lock(&socket->sending_lock); 257 258 /* Set the data fragment size */ 259 socket->data_fragment_size = 260 SOCKET_GET_DATA_FRAGMENT_SIZE(call); 261 262 fibril_rwlock_write_unlock(&socket->sending_lock); 263 } 264 265 fibril_rwlock_read_unlock(&socket_globals.lock); 266 break; 267 268 default: 269 rc = ENOTSUP; 270 } 271 272 async_answer_0(callid, (sysarg_t) rc); 273 goto loop; 277 278 async_answer_0(callid, (sysarg_t) rc); 279 } 274 280 } 275 281 … … 283 289 static async_sess_t *socket_get_tcp_sess(void) 284 290 { 285 if (socket_globals.tcp_sess == NULL) {286 socket_globals.tcp_sess = bind_service(SERVICE_TCP,291 if (socket_globals.tcp_sess == NULL) 292 socket_globals.tcp_sess = service_bind(SERVICE_TCP, 287 293 0, 0, SERVICE_TCP, socket_connection); 288 } 289 294 290 295 return socket_globals.tcp_sess; 291 296 } … … 300 305 static async_sess_t *socket_get_udp_sess(void) 301 306 { 302 if (socket_globals.udp_sess == NULL) {303 socket_globals.udp_sess = bind_service(SERVICE_UDP,307 if (socket_globals.udp_sess == NULL) 308 socket_globals.udp_sess = service_bind(SERVICE_UDP, 304 309 0, 0, SERVICE_UDP, socket_connection); 305 } 306 310 307 311 return socket_globals.udp_sess; 308 312 } … … 378 382 * @return Other error codes as defined for the NET_SOCKET message. 379 383 * @return Other error codes as defined for the 380 * bind_service() function.384 * service_bind() function. 381 385 */ 382 386 int socket(int domain, int type, int protocol) … … 393 397 switch (domain) { 394 398 case PF_INET: 399 case PF_INET6: 395 400 switch (type) { 396 401 case SOCK_STREAM: … … 431 436 break; 432 437 433 case PF_INET6:434 438 default: 435 439 return EPFNOSUPPORT; … … 444 448 return ENOMEM; 445 449 446 bzero(socket, sizeof(*socket)); 450 memset(socket, 0, sizeof(*socket)); 451 socket->family = domain; 447 452 fibril_rwlock_write_lock(&socket_globals.lock); 448 453 … … 655 660 return ENOMEM; 656 661 } 657 bzero(new_socket, sizeof(*new_socket));662 memset(new_socket, 0, sizeof(*new_socket)); 658 663 socket_id = socket_generate_new_id(); 659 664 if (socket_id <= 0) {
Note:
See TracChangeset
for help on using the changeset viewer.