Rev 1441 | Rev 1453 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1441 | Rev 1452 | ||
---|---|---|---|
Line 267... | Line 267... | ||
267 | void client_connection(ipc_callid_t callid, ipc_call_t *call) |
267 | void client_connection(ipc_callid_t callid, ipc_call_t *call) |
268 | { |
268 | { |
269 | ipc_answer_fast(callid, ENOENT, 0, 0); |
269 | ipc_answer_fast(callid, ENOENT, 0, 0); |
270 | } |
270 | } |
271 | 271 | ||
- | 272 | /** Function that gets created on interrupt receival |
|
- | 273 | * |
|
- | 274 | * This function is defined as a weak symbol - to be redefined in |
|
- | 275 | * user code. |
|
- | 276 | */ |
|
- | 277 | void interrupt_received(ipc_call_t *call) |
|
- | 278 | { |
|
- | 279 | } |
|
- | 280 | ||
- | 281 | ||
272 | /** Wrapper for client connection thread |
282 | /** Wrapper for client connection thread |
273 | * |
283 | * |
274 | * When new connection arrives, thread with this function is created. |
284 | * When new connection arrives, thread with this function is created. |
275 | * It calls client_connection and does final cleanup. |
285 | * It calls client_connection and does final cleanup. |
276 | * |
286 | * |
Line 306... | Line 316... | ||
306 | * Creates new thread for connection, fills in connection |
316 | * Creates new thread for connection, fills in connection |
307 | * structures and inserts it into the hash table, so that |
317 | * structures and inserts it into the hash table, so that |
308 | * later we can easily do routing of messages to particular |
318 | * later we can easily do routing of messages to particular |
309 | * threads. |
319 | * threads. |
310 | * |
320 | * |
- | 321 | * @param in_phone_hash Identification of the incoming connection |
|
311 | * @param callid Callid of the IPC_M_CONNECT_ME_TO packet |
322 | * @param callid Callid of the IPC_M_CONNECT_ME_TO packet |
312 | * @param call Call data of the opening packet |
323 | * @param call Call data of the opening packet |
313 | * @param cthread Thread function that should be called upon |
324 | * @param cthread Thread function that should be called upon |
314 | * opening the connection |
325 | * opening the connection |
315 | * @return New thread id |
326 | * @return New thread id |
316 | */ |
327 | */ |
317 | pstid_t async_new_connection(ipc_callid_t callid, ipc_call_t *call, |
328 | pstid_t async_new_connection(ipcarg_t in_phone_hash,ipc_callid_t callid, |
- | 329 | ipc_call_t *call, |
|
318 | void (*cthread)(ipc_callid_t,ipc_call_t *)) |
330 | void (*cthread)(ipc_callid_t,ipc_call_t *)) |
319 | { |
331 | { |
320 | pstid_t ptid; |
332 | pstid_t ptid; |
321 | connection_t *conn; |
333 | connection_t *conn; |
322 | unsigned long key; |
334 | unsigned long key; |
Line 324... | Line 336... | ||
324 | conn = malloc(sizeof(*conn)); |
336 | conn = malloc(sizeof(*conn)); |
325 | if (!conn) { |
337 | if (!conn) { |
326 | ipc_answer_fast(callid, ENOMEM, 0, 0); |
338 | ipc_answer_fast(callid, ENOMEM, 0, 0); |
327 | return NULL; |
339 | return NULL; |
328 | } |
340 | } |
329 | conn->in_phone_hash = IPC_GET_ARG3(*call); |
341 | conn->in_phone_hash = in_phone_hash; |
330 | list_initialize(&conn->msg_queue); |
342 | list_initialize(&conn->msg_queue); |
331 | conn->ptid = psthread_create(connection_thread, conn); |
343 | conn->ptid = psthread_create(connection_thread, conn); |
332 | conn->callid = callid; |
344 | conn->callid = callid; |
333 | conn->call = *call; |
345 | conn->call = *call; |
334 | conn->active = 1; /* We will activate it asap */ |
346 | conn->active = 1; /* We will activate it asap */ |
Line 351... | Line 363... | ||
351 | } |
363 | } |
352 | 364 | ||
353 | /** Handle call that was received */ |
365 | /** Handle call that was received */ |
354 | static void handle_call(ipc_callid_t callid, ipc_call_t *call) |
366 | static void handle_call(ipc_callid_t callid, ipc_call_t *call) |
355 | { |
367 | { |
356 | if (route_call(callid, call)) |
368 | /* Unrouted call - do some default behaviour */ |
357 | return; |
- | |
358 | - | ||
359 | switch (IPC_GET_METHOD(*call)) { |
369 | switch (IPC_GET_METHOD(*call)) { |
360 | case IPC_M_INTERRUPT: |
370 | case IPC_M_INTERRUPT: |
- | 371 | interrupt_received(call); |
|
361 | break; |
372 | return; |
362 | case IPC_M_CONNECT_ME_TO: |
373 | case IPC_M_CONNECT_ME_TO: |
363 | /* Open new connection with thread etc. */ |
374 | /* Open new connection with thread etc. */ |
364 | async_new_connection(callid, call, client_connection); |
375 | async_new_connection(IPC_GET_ARG3(*call), callid, call, client_connection); |
365 | break; |
376 | return; |
366 | default: |
- | |
367 | ipc_answer_fast(callid, EHANGUP, 0, 0); |
- | |
368 | } |
377 | } |
- | 378 | ||
- | 379 | /* Try to route call through connection tables */ |
|
- | 380 | if (route_call(callid, call)) |
|
- | 381 | return; |
|
- | 382 | ||
- | 383 | /* Unknown call from unknown phone - hang it up */ |
|
- | 384 | ipc_answer_fast(callid, EHANGUP, 0, 0); |
|
369 | } |
385 | } |
370 | 386 | ||
371 | /** Fire all timeouts that expired */ |
387 | /** Fire all timeouts that expired */ |
372 | static void handle_expired_timeouts(void) |
388 | static void handle_expired_timeouts(void) |
373 | { |
389 | { |
Line 619... | Line 635... | ||
619 | free(msg); |
635 | free(msg); |
620 | 636 | ||
621 | return 0; |
637 | return 0; |
622 | } |
638 | } |
623 | 639 | ||
- | 640 | /** Wait specified time, but in the meantime handle incoming events |
|
- | 641 | * |
|
- | 642 | * @param timeout Time in microseconds to wait |
|
- | 643 | */ |
|
- | 644 | void async_usleep(suseconds_t timeout) |
|
- | 645 | { |
|
- | 646 | amsg_t *msg; |
|
- | 647 | ||
- | 648 | msg = malloc(sizeof(*msg)); |
|
- | 649 | if (!msg) |
|
- | 650 | return; |
|
- | 651 | ||
- | 652 | msg->ptid = psthread_get_id(); |
|
- | 653 | msg->active = 0; |
|
- | 654 | msg->has_timeout = 1; |
|
- | 655 | ||
- | 656 | gettimeofday(&msg->expires, NULL); |
|
- | 657 | tv_add(&msg->expires, timeout); |
|
- | 658 | ||
- | 659 | futex_down(&async_futex); |
|
- | 660 | insert_timeout(msg); |
|
- | 661 | /* Leave locked async_futex when entering this function */ |
|
- | 662 | psthread_schedule_next_adv(PS_TO_MANAGER); |
|
- | 663 | /* futex is up automatically after psthread_schedule_next...*/ |
|
- | 664 | free(msg); |
|
- | 665 | } |