1 /*DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64
4 for INTEL64(R), AMD64(R)
6 Copyright(C) 2007-2009 Koine Yuusuke(koinec). All rights reserved.
8 Redistribution and use in source and binary forms, with or without
9 modification, are permitted provided that the following conditions are met:
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.
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.
29 DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64*/
31 /* File Info -----------------------------------------------------------
35 ----------------------------------------------------------------------*/
37 #include"drd64_server.h"
38 #define DRD64_SRC_SERVER_RECVSTATUS
39 #include"drd64_server_recvstatus.h"
41 Drd64_Server_RecvStatus **gpp_recvstat;
42 Drd64_Server_RecvStatus *gp_recvalloc;
48 EXTERN_SERVER_RECVSTATUS
50 Drd64_Server_RecvStatus_Init(
56 gpp_recvstat = (Drd64_Server_RecvStatus **)malloc(
57 sizeof( Drd64_Server_RecvStatus *) * FD_SETSIZE );
58 if( NULL == gpp_recvstat ) {
64 gp_recvalloc = (Drd64_Server_RecvStatus *)malloc(
65 sizeof( Drd64_Server_RecvStatus )
67 if( NULL == gp_recvalloc ) {
73 memset( gpp_recvstat, 0x00,
74 sizeof( Drd64_Server_RecvStatus *) * FD_SETSIZE );
76 memset( gp_recvalloc, 0x00,
77 sizeof( Drd64_Server_RecvStatus )
79 for( i_cnt = 0; i_cnt < i_alloc_units; i_cnt++ ) {
80 (gp_recvalloc + i_cnt)->i_fds_id = -1;
81 pv_temp = malloc( DRD64_MAX_PACKET_LENGTH );
82 if( NULL == pv_temp ) { break; }
84 (gp_recvalloc + i_cnt)->pv_buf = pv_temp;
87 if( NULL == pv_temp ) {
88 for( ; i_cnt >= 0; i_cnt-- ) {
89 free( (gp_recvalloc + i_cnt)->pv_buf );
90 (gp_recvalloc + i_cnt)->pv_buf = NULL;
103 gi_recvalloc_max = i_alloc_units;
104 gi_recvalloc_now = 0;
110 EXTERN_SERVER_RECVSTATUS
112 Drd64_Server_RecvStatus_Term(
117 for( i_cnt = 0; i_cnt < gi_recvalloc_max; i_cnt++ ) {
118 free( (gp_recvalloc + i_cnt)->pv_buf );
119 (gp_recvalloc + i_cnt)->pv_buf = NULL;
122 free( gp_recvalloc );
123 gi_recvalloc_max = 0;
124 gi_recvalloc_now = 0;
127 free( gpp_recvstat );
134 EXTERN_SERVER_RECVSTATUS
135 Drd64_Server_RecvStatus *
136 Drd64_Server_RecvStatus_AllocRecvStatus(
141 Drd64_Server_RecvStatus *p_recv;
142 Drd64_Server_RecvStatus *p_temp;
146 if( gi_recvalloc_now >= gi_recvalloc_max ) {
147 for( i_cnt = 0; i_cnt < gi_recvalloc_max; i_cnt++ ) {
148 if( -1 == (gp_recvalloc + i_cnt)->i_fds_id ) {
149 p_recv = (gp_recvalloc + i_cnt);
154 if( NULL == p_recv ) {
155 p_temp = realloc( gp_recvalloc,
156 gi_recvalloc_max + i_alloc_units );
157 if( NULL == p_temp ) { return NULL; }
159 for( i_cnt = gi_recvalloc_max;
160 i_cnt < i_alloc_units + gi_recvalloc_max;
162 (gp_recvalloc + i_cnt)->i_fds_id = -1;
165 gp_recvalloc = p_temp;
166 gi_recvalloc_max += i_alloc_units;
167 p_recv = gp_recvalloc + gi_recvalloc_now++;
171 p_recv = gp_recvalloc + gi_recvalloc_now++;
174 p_recv->i_fds_id = i_fds;
175 *(gpp_recvstat + i_fds) = p_recv;
176 if( i_fds + 1 > gi_recvstat_max )
177 { gi_recvstat_max = i_fds + 1; }
183 EXTERN_SERVER_RECVSTATUS
185 Drd64_Server_RecvStatus_FreeRecvStatus(
189 Drd64_Server_RecvStatus *p_recv_now;
190 Drd64_Server_RecvStatus *p_recv_temp;
192 p_recv_now = *(gpp_recvstat + i_fds);
194 if( NULL != p_recv_now ) {
195 *(gpp_recvstat + i_fds) = NULL;
197 if( i_fds + 1 == gi_recvstat_max ) {
198 for( i_cnt = i_fds+1; i_cnt > 0; i_cnt-- ) {
199 p_recv_temp = *(gpp_recvstat + i_cnt);
200 if( NULL != p_recv_temp ) {
201 gi_recvstat_max = i_cnt + 1;
206 if( 0 == i_cnt ) { gi_recvstat_max = 0; }
209 p_recv_now->i_fds_id = -1;
216 EXTERN_SERVER_RECVSTATUS
217 Drd64_Server_RecvStatus *
218 Drd64_Server_RecvStatus_GetRecvStatus(
221 return *(gpp_recvstat + i_fds);
225 EXTERN_SERVER_RECVSTATUS
227 Drd64_Server_RecvStatus_GetPacketStatus(
230 Drd64_Server_RecvStatus *p_recv;
231 p_recv = *(gpp_recvstat + i_fds);
233 if( NULL == p_recv ) { return -1; }
235 return p_recv->b_recv_status;
239 EXTERN_SERVER_RECVSTATUS
241 Drd64_Server_RecvStatus_GetCmdStatus(
244 Drd64_Server_RecvStatus *p_recv;
245 p_recv = *(gpp_recvstat + i_fds);
247 if( NULL == p_recv ) { return -1; }
249 return p_recv->i_command_status;
253 EXTERN_SERVER_RECVSTATUS
255 Drd64_Server_RecvStatus_SetCmdStatus(
257 int i_command_status )
259 Drd64_Server_RecvStatus *p_recv;
260 p_recv = *(gpp_recvstat + i_fds);
262 if( NULL == p_recv ) { return -1; }
264 p_recv->i_command_status = i_command_status;
266 return p_recv->i_command_status;
270 EXTERN_SERVER_RECVSTATUS
272 Drd64_Server_RecvStatus_GetRecvStatMax(
275 return gi_recvstat_max;
278 /* EOF of drd64_.c ----------------------------------- */