summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/tests/AVStreams/benchmark/child.cpp
blob: 665dc2511bbd7ae17529fd81b7ad20c059b536a2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
// $Id$

#include "child.h"
#include "tao/ORB_Core.h"

ACE_RCSID(benchmark, child, "$Id$")

Server_Globals::Server_Globals (void)
  :ready_cond_ (ready_mtx_),
   hostname_ (0),
   port_ (0)
{
}


int
Server_Globals::parse_args (int argc,char **argv)
{
  ACE_Get_Opt opts (argc,argv,"pa:r");

  char child_name [BUFSIZ], buf[BUFSIZ];
  ACE_OS::strcpy (child_name,"child_process");
  this->strategy_ = REACTIVE_STRATEGY;
  int c;
  while ((c = opts ()) != -1)
    {
      switch (c)
        {
        case 'p':
          // process based strategy
          this->strategy_  = PROCESS_STRATEGY;
          break;
        case 'a':
          ACE_NEW_RETURN (addr_,
                          ACE_INET_Addr (opts.optarg),
                          -1);
          this->port_ = this->addr_->get_port_number ();
          this->hostname_ = (char*) this->addr_->get_host_name ();
          break;
        case 'r':
          //Reactive Stratgey
          this->strategy_  = REACTIVE_STRATEGY;
          break;
        case 'c':
          ACE_OS::strcpy (child_name,opts.optarg);
          break;
        default:
          ACE_ERROR_RETURN ((LM_ERROR,"Usage: server [-p/-r]"),-1);
        }
    }
  ACE_OS::sprintf (buf,"%s -ORBobjrefstyle url",child_name);
  this->process_options_.command_line (buf);
  return 0;
}

// Bench_Server_StreamEndPoint methods.
Bench_Server_StreamEndPoint::Bench_Server_StreamEndPoint (void)
{
}

int
Bench_Server_StreamEndPoint::handle_open (void) 
{
  return 0;
}

int
Bench_Server_StreamEndPoint::handle_close (void) 
{
  return 0;
}

int
Bench_Server_StreamEndPoint::handle_stop (const AVStreams::flowSpec &/* the_spec */,
                                          CORBA::Environment &/* env */) 
{
  return 0;
}
  
int
Bench_Server_StreamEndPoint::handle_start (const AVStreams::flowSpec &/* the_spec */,  
                                           CORBA::Environment &/* env */) 
{
 return 0;
}
  
int
Bench_Server_StreamEndPoint::handle_destroy (const AVStreams::flowSpec &/* the_spec */,  
                                             CORBA::Environment &/* env */) 
{
  return 0;
}

CORBA::Boolean 
Bench_Server_StreamEndPoint::handle_connection_requested (AVStreams::flowSpec &the_spec,  
                                                          CORBA::Environment &/* env */) 
{

  ACE_DEBUG ((LM_DEBUG,
              "(%P|%t) Bench_Server_StreamEndPoint::handle_connection_requested:() length =%d\n",
              the_spec.length ()));
  
  char buf [BUFSIZ];
  SERVER_GLOBALS::instance ()->addr_->addr_to_string (buf, BUFSIZ);
  ACE_INET_Addr client_addr (buf);
  
  u_short local_port = 0;
  ACE_INET_Addr local_addr (local_port);
  
  if (this->connector_.connect (this->tcp_stream_,
                                client_addr,
                                0,
                                local_addr) == -1)
    ACE_ERROR_RETURN ((LM_ERROR,
                       "(%P|%t) Connection to server failed: %p\n",
                       "connect "),
                      0);
  
  ACE_DEBUG ((LM_DEBUG,
              "(%P|%t) tcp connect succeeded %d\n",
              this->tcp_stream_.get_handle ()));
  
  int sndbufsize = ACE_DEFAULT_MAX_SOCKET_BUFSIZ;
  int rcvbufsize = ACE_DEFAULT_MAX_SOCKET_BUFSIZ;
  
  if (this->tcp_stream_.set_option (SOL_SOCKET,
                                    SO_SNDBUF,
                                    (void *) &sndbufsize,
                                    sizeof (sndbufsize)) == -1
      && errno != ENOTSUP)
    return 0;
  else if (this->tcp_stream_.set_option (SOL_SOCKET,
                                         SO_RCVBUF,
                                         (void *) &rcvbufsize,
                                         sizeof (rcvbufsize)) == -1
           && errno != ENOTSUP)
    return 0;
  
  int one = 1;
  if (this->tcp_stream_.set_option (SOL_SOCKET,
                                    TCP_NODELAY,
                                    (char *)& one,
                                    sizeof (one)) == -1 )
    return 0;
  
  ACE_NEW_RETURN (this->stream_handler_,
                  ttcp_Stream_Handler (this->tcp_stream_.get_handle ()),
                  0);
  int result;
  
  result = TAO_ORB_Core_instance ()->reactor ()->register_handler (this->stream_handler_,
                                                                   ACE_Event_Handler::READ_MASK);
  if (result < 0)
    return 0;
  
  ACE_DEBUG ((LM_DEBUG,
              "(%P|%t) register handler for tcp_Stream success\n"));
  return 1;
}


ttcp_Stream_Handler::ttcp_Stream_Handler (ACE_HANDLE control_fd)
  : control_handle_ (control_fd)
{
}

// Called by the reactor to extract the handle associated with this handler.
ACE_HANDLE
ttcp_Stream_Handler::get_handle (void) const
{
  return this->control_handle_ ;
}

// Called by the Reactor when data is ready to be read from the
// video control handle, which indicates a control message from the client.
int
ttcp_Stream_Handler::handle_input (ACE_HANDLE /* handle */)
{
  char buf[BUFSIZ];
  int result = ACE_OS::read (this->control_handle_,buf,BUFSIZ);
  if (result < 0 )
    ACE_ERROR_RETURN ((LM_ERROR,
                       "(%P|%t) Bench_Server_StreamEndPoint::handle_input ()\n"),
                      -1);

  if (result == 0)
    return 0;
  return 0;
}

#if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION)
template class ACE_Singleton<Server_Globals,TAO_SYNCH_MUTEX>;
#elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA)
#pragma instantiate ACE_Singleton <Server_Globals,TAO_SYNCH_MUTEX> 
#endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */