Changeset 06b0211b in mainline for uspace/lib/c/generic/net/socket_client.c
- Timestamp:
- 2013-04-29T11:29:45Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- aa2b32c
- Parents:
- ba4799a (diff), df956b9b (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
rba4799a r06b0211b 192 192 /** Default thread for new connections. 193 193 * 194 * @param[in] iid The initial message identifier. 195 * @param[in] icall The initial message call structure. 196 * @param[in] arg Local argument. 194 * @param[in] iid The initial message identifier. 195 * @param[in] icall The initial message call structure. 196 * @param[in] arg Local argument. 197 * 197 198 */ 198 199 static void socket_connection(ipc_callid_t iid, ipc_call_t * icall, void *arg) 199 200 { 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; 201 while (true) { 202 ipc_call_t call; 203 ipc_callid_t callid = async_get_call(&call); 204 205 if (!IPC_GET_IMETHOD(call)) { 206 async_answer_0(callid, 0); 207 return; 221 208 } 209 210 int rc; 222 211 223 212 switch (IPC_GET_IMETHOD(call)) { 224 213 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); 214 case NET_SOCKET_ACCEPTED: 215 case NET_SOCKET_DATA_FRAGMENT_SIZE: 216 fibril_rwlock_read_lock(&socket_globals.lock); 217 218 /* Find the socket */ 219 socket_t *socket = sockets_find(socket_get_sockets(), 220 SOCKET_GET_SOCKET_ID(call)); 221 if (!socket) { 222 rc = ENOTSOCK; 223 fibril_rwlock_read_unlock(&socket_globals.lock); 224 break; 233 225 } 234 fibril_mutex_unlock(&socket->receive_lock); 226 227 switch (IPC_GET_IMETHOD(call)) { 228 case NET_SOCKET_RECEIVED: 229 fibril_mutex_lock(&socket->receive_lock); 230 /* Push the number of received packet fragments */ 231 rc = dyn_fifo_push(&socket->received, 232 SOCKET_GET_DATA_FRAGMENTS(call), 233 SOCKET_MAX_RECEIVED_SIZE); 234 if (rc == EOK) { 235 /* Signal the received packet */ 236 fibril_condvar_signal(&socket->receive_signal); 237 } 238 fibril_mutex_unlock(&socket->receive_lock); 239 break; 240 241 case NET_SOCKET_ACCEPTED: 242 /* Push the new socket identifier */ 243 fibril_mutex_lock(&socket->accept_lock); 244 rc = dyn_fifo_push(&socket->accepted, 1, 245 SOCKET_MAX_ACCEPTED_SIZE); 246 if (rc == EOK) { 247 /* Signal the accepted socket */ 248 fibril_condvar_signal(&socket->accept_signal); 249 } 250 fibril_mutex_unlock(&socket->accept_lock); 251 break; 252 253 default: 254 rc = ENOTSUP; 255 } 256 257 if ((SOCKET_GET_DATA_FRAGMENT_SIZE(call) > 0) && 258 (SOCKET_GET_DATA_FRAGMENT_SIZE(call) != 259 socket->data_fragment_size)) { 260 fibril_rwlock_write_lock(&socket->sending_lock); 261 262 /* Set the data fragment size */ 263 socket->data_fragment_size = 264 SOCKET_GET_DATA_FRAGMENT_SIZE(call); 265 266 fibril_rwlock_write_unlock(&socket->sending_lock); 267 } 268 269 fibril_rwlock_read_unlock(&socket_globals.lock); 235 270 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 271 249 272 default: 250 273 rc = ENOTSUP; 251 274 } 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; 275 276 async_answer_0(callid, (sysarg_t) rc); 277 } 274 278 } 275 279
Note:
See TracChangeset
for help on using the changeset viewer.