OSDN Git Service

(LibGoblin)
[drdeamon64/drdeamon64.git] / deamon / drd64_marshald_cmd_connect_count.c
1 /*DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64
2
3                          D r . D e a m o n  6 4
4                         for INTEL64(R), AMD64(R)
5         
6    Copyright(C) 2007-2009 Koine Yuusuke(koinec). All rights reserved.
7
8 Redistribution and use in source and binary forms, with or without
9 modification, are permitted provided that the following conditions are met:
10
11  1. Redistributions of source code must retain the above copyright notice,
12     this list of conditions and the following disclaimer.
13  2. Redistributions in binary form must reproduce the above copyright
14     notice, this list of conditions and the following disclaimer in the
15     documentation and/or other materials provided with the distribution.
16
17 THIS SOFTWARE IS PROVIDED BY Koine Yuusuke(koinec) ``AS IS'' AND ANY
18 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 DISCLAIMED. IN NO EVENT SHALL Koine Yuusuke(koinec) OR CONTRIBUTORS BE
21 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
27 OF THE POSSIBILITY OF SUCH DAMAGE.
28
29 DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64*/
30
31 /* File Info -----------------------------------------------------------
32 File: drd64_.c
33 Function: 
34 Comment: 
35 ----------------------------------------------------------------------*/
36
37 #include"drd64_marshald.h"
38
39
40 /*----------------------------------------------------------------------
41 static int
42         Drd64_Intel64_DisAsm_GetSize_SizeID(
43                 : Get Operand Size form Intel 64 DB SizeID
44
45                 int i_operandsize,      : [src] Default Operand Size
46                 Word w_methodtype,      : [src] Method Type ID
47                 Word w_sizeid )         : [src] Size ID
48 ----------------------------------------------------------------------*/
49 int
50         Drd64_Marshald_Cmd_ConnectCount_Client(
51                 int             i_fds,
52                 Drd64_PacketHeader      *p_phead,
53                 Drd64_PacketData_ConnectCount   *p_ccount )
54 {
55         Drd64_Marshald_ConnectInfo      *p_cinfo;
56
57         DRD64_LOG_DEBUG("  [DEBUG] CMD: ConnectCount(Client) Start");
58         
59         p_cinfo = Drd64_Marshald_CInfo_GetConnectInfo(
60                                                                         p_phead->i_cid_src );
61         assert( NULL != p_cinfo );
62
63         p_cinfo->i_cinfo_refcount       += p_ccount->i_refcount_diff;
64
65         if( p_cinfo->i_cinfo_refcount != p_ccount->i_refcount_server )  {
66                 DRD64_LOG_DEBUG("  [DEBUG] CMD: ConnectCount(Client) Error");
67         }
68
69         if( 0 == p_cinfo->i_cinfo_refcount )    {
70                 Drd64_Marshald_Dispatch_CloseSocket( p_cinfo->i_dest_socket );
71                 //Drd64_Marshald_Cinfo_FreeConnectInfo( p_cinfo );
72                 //p_cinfo     = NULL;
73                 DRD64_LOG_DEBUG("  [DEBUG] CMD: ConnectCount(Client) DisConnect");
74         }
75
76         DRD64_LOG_DEBUG("  [DEBUG] CMD: ConnectCount(Client) Ended");
77
78         return DRD64_MARSHALD_DISPATCH_RESULT_RESTART;
79 }
80
81
82 /*----------------------------------------------------------------------
83 ----------------------------------------------------------------------*/
84 int
85         Drd64_Marshald_Cmd_ConnectCount_Server(
86                 int             i_recv_id,
87                 Drd64_PacketHeader      *p_phead,
88                 Drd64_PacketData_ConnectCount   *p_ccount )
89 {
90         int                     i_wlen;
91         int                     i_fds;
92         Drd64_Marshald_ConnectInfo              *p_cinfo;
93         Drd64_Server_RecvStatus                 *p_recv;
94
95         DRD64_LOG_DEBUG("  [DEBUG] CMD: ConnectCount(Server) Start");
96
97         p_recv  = Drd64_Server_RecvStatus_GetRecvStatus( i_recv_id );
98         assert( NULL != p_recv );
99         i_fds   = p_recv->i_fds_id;
100         
101         /* Alloc ConnectInfo. */
102         p_cinfo = Drd64_Marshald_CInfo_GetConnectInfo( p_phead->i_cid_dest );
103         assert( NULL != p_cinfo );
104
105         p_cinfo->i_cinfo_refcount       += p_ccount->i_refcount_diff; 
106         /* XXX : Connection Lock
107         if( 0 == p_cinfo->i_cinfo_refcount )    {
108                 // Connection LOCK!
109         }
110         */
111
112         /* Set Answer Data ---------*/
113         p_phead->w_packettype           |= DRD64_PACKETTYPE_FLAG_ANSWER;
114         p_ccount->i_refcount_server     = p_cinfo->i_cinfo_refcount;
115
116         i_wlen  = send( i_fds, (void *)p_phead, DRD64_PacketSize(p_phead), 0x00 );
117         DRD64_DEBUG_PRINT("send",i_wlen,"FD",i_fds,"errno",errno);
118         if( i_wlen != DRD64_PacketSize(p_phead) )
119                 { return DRD64_MARSHALD_DISPATCH_RESULT_CLOSE; }        // XXX > error
120         
121         DRD64_LOG_DEBUG("  [DEBUG] CMD: ConnectCount(Server) Complete ");
122
123         return DRD64_MARSHALD_DISPATCH_RESULT_COMPLETE;
124 }
125
126
127 /*----------------------------------------------------------------------
128 ----------------------------------------------------------------------*/
129 int
130         Drd64_Marshald_Cmd_ConnectCount(
131                 int             i_recv_id,
132                 Drd64_PacketHeader      *p_phead,
133                 Drd64_PacketData_ConnectCount   *p_ccount )
134 {
135         int             i_result;
136
137         DRD64_LOG_VERBOSE("[STAT]CMD: Connect Count Start");
138         
139         if( DRD64_IsPacketType_Answer( p_phead ) )      {
140                 i_result        = Drd64_Marshald_Cmd_ConnectCount_Client(
141                                                                 i_recv_id, p_phead, p_ccount );
142
143         }
144         else    {
145                 i_result        = Drd64_Marshald_Cmd_ConnectCount_Server(
146                                                                 i_recv_id, p_phead, p_ccount );
147         }
148         
149         DRD64_LOG_VERBOSE("[STAT]CMD: Connect Count Ended");
150
151         return i_result;
152 }
153
154
155 /* EOF of drd64_.c ----------------------------------- */