annotate freeDiameter/p_out.c @ 33:e6fcdf12b9a0

Added a lot of TODOs :)
author Sebastien Decugis <sdecugis@nict.go.jp>
date Thu, 29 Oct 2009 18:05:45 +0900
parents
children 0e2b57789361
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
33
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1 /*********************************************************************************************************
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2 * Software License Agreement (BSD License) *
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
3 * Author: Sebastien Decugis <sdecugis@nict.go.jp> *
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
4 * *
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
5 * Copyright (c) 2009, WIDE Project and NICT *
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
6 * All rights reserved. *
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
7 * *
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
8 * Redistribution and use of this software in source and binary forms, with or without modification, are *
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
9 * permitted provided that the following conditions are met: *
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
10 * *
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
11 * * Redistributions of source code must retain the above *
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
12 * copyright notice, this list of conditions and the *
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
13 * following disclaimer. *
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
14 * *
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
15 * * Redistributions in binary form must reproduce the above *
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
16 * copyright notice, this list of conditions and the *
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
17 * following disclaimer in the documentation and/or other *
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
18 * materials provided with the distribution. *
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
19 * *
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
20 * * Neither the name of the WIDE Project or NICT nor the *
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
21 * names of its contributors may be used to endorse or *
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
22 * promote products derived from this software without *
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
23 * specific prior written permission of WIDE Project and *
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
24 * NICT. *
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
25 * *
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED *
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
27 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
28 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR *
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
29 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT *
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
30 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS *
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
31 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR *
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
32 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF *
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
33 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
34 *********************************************************************************************************/
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
35
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
36 #include "fD.h"
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
37
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
38 /* Alloc a new hbh for requests, bufferize the message and send on the connection, save in sentreq if provided */
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
39 static int do_send(struct msg ** msg, struct cnxctx * cnx, uint32_t * hbh, struct fd_list * sentreq)
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
40 {
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
41 TRACE_ENTRY("%p %p %p %p", msg, cnx, hbh, sentreq);
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
42
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
43 TODO("If message is a request");
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
44 TODO("Alloc new *hbh");
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
45
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
46 TODO("Bufferize the message, send it");
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
47
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
48 TODO("Save in sentreq or free")
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
49
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
50 return ENOTSUP;
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
51 }
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
52
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
53 /* The code of the "out" thread */
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
54 static void * out_thr(void * arg)
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
55 {
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
56 TODO("Pick next message in peer->p_tosend");
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
57 TODO("do_send, log errors");
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
58 TODO("In case of cancellation, requeue the message");
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
59 return NULL;
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
60 error:
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
61 TODO(" Send an event to the peer ");
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
62 return NULL;
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
63 }
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
64
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
65 /* Wrapper to sending a message either by out thread (peer in OPEN state) or directly; cnx or peer must be provided */
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
66 int fd_out_send(struct msg ** msg, struct cnxctx * cnx, struct fd_peer * peer)
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
67 {
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
68 TRACE_ENTRY("%p %p %p", msg, cnx, peer);
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
69 CHECK_PARAMS( msg && *msg && (cnx || (peer && peer->p_cnxctx)));
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
70
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
71 if (peer && (peer->p_hdr.info.pi_state == STATE_OPEN)) {
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
72 /* Normal case: just queue for the out thread to pick it up */
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
73 CHECK_FCT( fd_fifo_post(peer->p_tosend, msg) );
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
74
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
75 } else {
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
76 uint32_t *hbh = NULL;
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
77
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
78 /* In other cases, the thread is not running, so we handle the sending directly */
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
79 if (peer)
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
80 hbh = &peer->p_hbh;
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
81
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
82 if (!cnx)
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
83 cnx = peer->p_cnxctx;
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
84
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
85 /* Do send the message */
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
86 CHECK_FCT( do_send(msg, cnx, hbh, peer ? &peer->p_sentreq : NULL) );
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
87 }
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
88
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
89 return 0;
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
90 }
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
91
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
92 /* Start the "out" thread that picks messages in p_tosend and send them on p_cnxctx */
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
93 int fd_out_start(struct fd_peer * peer)
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
94 {
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
95 TRACE_ENTRY("%p", peer);
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
96 CHECK_PARAMS( CHECK_PEER(peer) && (peer->p_outthr == (pthread_t)NULL) );
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
97
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
98 CHECK_POSIX( pthread_create(&peer->p_outthr, NULL, out_thr, peer) );
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
99
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
100 return 0;
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
101 }
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
102
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
103 /* Stop that thread */
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
104 int fd_out_stop(struct fd_peer * peer)
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
105 {
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
106 TRACE_ENTRY("%p", peer);
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
107 CHECK_PARAMS( CHECK_PEER(peer) );
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
108
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
109 CHECK_FCT( fd_thr_term(&peer->p_outthr) );
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
110
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
111 return 0;
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
112 }
e6fcdf12b9a0 Added a lot of TODOs :)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
113
"Welcome to our mercurial repository"