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