本文整理汇总了C++中ACE_SOCK_Connector类的典型用法代码示例。如果您正苦于以下问题:C++ ACE_SOCK_Connector类的具体用法?C++ ACE_SOCK_Connector怎么用?C++ ACE_SOCK_Connector使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ACE_SOCK_Connector类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char** argv){
if(argc < 2){
cerr << "Invalid arguments!"<<endl;
return returnType::invalid_argument;
}
const unsigned short port = 2000;
ACE_INET_Addr addr(port, ACE_LOCALHOST);
ACE_SOCK_Connector connector;
ACE_SOCK_Stream stream;
if(connector.connect(stream,addr) < 0){
cerr << endl << "Can not connect to server!" <<endl;
return -1;
}
Client *client;
ACE_NEW_RETURN(client, Client(argc, argv, stream), -1);
ACE_Time_Value value(3,0);
ACE_Reactor::instance()->schedule_timer(client, 0, value, value);
while(true){
if(SignalHandler::is_interrupted()){
break;
}
ACE_Reactor::instance()->handle_events();
}
return returnType::success;
}
示例2: connectGate
void ManageGateSession::connectGate()
{
const GateCfgVec_t & gate_cfg_vec = ManageConfig::instance()->getGateCfg();
ACE_SOCK_Connector connector;
ACE_INET_Addr addr;
for (GateCfgVec_t::const_iterator it = gate_cfg_vec.begin(); it != gate_cfg_vec.end(); )
{
addr.set(it->port, it->ip.c_str());
GateSession * gate_session = new GateSession();
if (connector.connect(gate_session->peer(), addr) == -1)
{
DEF_LOG_ERROR("Failed to connector gate, ip is <%s>, port is <%d>, last error is <%d>\n", it->ip.c_str(), it->port, ACE_OS::last_error());
ACE_OS::sleep(1);
continue;
}
else
{
gate_session->setPacketHandler(RouteGatePacket::instance());
gate_session->netConnected();
gate_session->peer().enable(ACE_NONBLOCK);
int flag = 1;
gate_session->peer().set_option(IPPROTO_TCP, TCP_NODELAY, (char *)&flag, sizeof(flag));
m_reactor->register_handler(gate_session, ACE_Event_Handler::READ_MASK);
++it;
}
}
}
示例3: sizeof
void
ACE::HTBP::Session::reconnect_i (ACE::HTBP::Channel *s) const
{
ACE_SOCK_Connector conn;
if (conn.connect (s->ace_stream(),*this->proxy_addr_) == -1)
{
ACE_TCHAR buffer[128];
this->proxy_addr_->addr_to_string(buffer, 128, 0);
ACE_ERROR ((LM_ERROR,
ACE_TEXT("(%P|%t) ACE::HTBP::Session::reconnect")
ACE_TEXT(" failed to %s, %p\n"),
buffer, s == this->inbound_ ?
ACE_TEXT("inbound") : ACE_TEXT ("outbound")));
}
else
{
#if !defined (ACE_LACKS_TCP_NODELAY)
int no_delay = 1;
int result = s->ace_stream().set_option (ACE_IPPROTO_TCP,
TCP_NODELAY,
(void *) &no_delay,
sizeof (no_delay));
if (result == -1)
ACE_DEBUG ((LM_DEBUG, "HTBP::Session::reconnect_i, %p\n", "set_option" ));
#endif /* ! ACE_LACKS_TCP_NODELAY */
}
s->register_notifier(this->reactor_);
if (s == this->inbound_)
s->send_ack();
}
示例4: tv
int extractCron::do_job(char *jobdesc)
{
ACE_SOCK_Connector conn;
ACE_SOCK_Stream peer;
ACE_Time_Value tv(3, 0);
ACE_INET_Addr addr(harvestPort, harvestIPaddr);
char urlbuff[1024];
StrStream httpreq;
int ret;
printf("JobDesc: %s\n", jobdesc);
CGI::escape(urlbuff, jobdesc);
httpreq.init(2); // 2 kilobytes buff
httpreq.rawadd("GET /harvest?expr=");
httpreq.rawadd(urlbuff);
httpreq.rawadd(" HTTP/1.1\n\n");
httpreq.print();
if ( conn.connect(peer, addr) < 0) {
printf("conn failed!\n");
return 0;
}
ret = peer.send( httpreq.str(), httpreq.len() );
return 0;
}
示例5: factory_addr
int
FT_EventService::report_factory(CORBA::ORB_ptr orb,
FtRtecEventChannelAdmin::EventChannel_ptr ec)
{
try{
char* addr = ACE_OS::getenv("EventChannelFactoryAddr");
if (addr != 0) {
// instaniated by object factory, report my ior back to the factory
ACE_INET_Addr factory_addr(addr);
ACE_SOCK_Connector connector;
ACE_SOCK_Stream stream;
ORBSVCS_DEBUG((LM_DEBUG,"connecting to %s\n",addr));
if (connector.connect(stream, factory_addr) == -1)
ORBSVCS_ERROR_RETURN((LM_ERROR, "(%P|%t) Invalid Factory Address\n"), -1);
ORBSVCS_DEBUG((LM_DEBUG,"Factory connected\n"));
CORBA::String_var my_ior_string = orb->object_to_string(ec);
int len = ACE_OS::strlen(my_ior_string.in()) ;
if (stream.send_n(my_ior_string.in(), len) != len)
ORBSVCS_ERROR_RETURN((LM_ERROR, "(%P|%t) IOR Transmission Error\n"), -1);
stream.close();
}
}
catch (...){
return -1;
}
return 0;
}
示例6: client
static void *
client (void *arg)
{
ACE_INET_Addr *remote_addr = (ACE_INET_Addr *) arg;
ACE_INET_Addr server_addr (remote_addr->get_port_number (),
ACE_IPV6_LOCALHOST);
ACE_SOCK_Stream cli_stream;
ACE_SOCK_Connector con;
ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%P|%t) starting non-blocking connect\n")));
// Initiate timed, non-blocking connection with server.
// Attempt a non-blocking connect to the server.
if (con.connect (cli_stream, server_addr,
(ACE_Time_Value *) &ACE_Time_Value::zero) == -1)
{
if (errno != EWOULDBLOCK)
ACE_ERROR ((LM_ERROR, ACE_TEXT ("(%P|%t) %p\n"), ACE_TEXT ("connection failed")));
ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%P|%t) starting timed connect\n")));
// Check if non-blocking connection is in progress,
// and wait up to ACE_DEFAULT_TIMEOUT seconds for it to complete.
ACE_Time_Value tv (ACE_DEFAULT_TIMEOUT);
if (con.complete (cli_stream, &server_addr, &tv) == -1)
ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("(%P|%t) %p\n"), ACE_TEXT ("connection failed")), 0);
else
ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%P|%t) connected to %C\n"),
server_addr.get_host_name ()));
}
if (cli_stream.disable (ACE_NONBLOCK) == -1)
ACE_ERROR ((LM_ERROR, ACE_TEXT ("(%P|%t) %p\n"), ACE_TEXT ("disable")));
// Send data to server (correctly handles "incomplete writes").
for (const char *c = ACE_ALPHABET; *c != '\0'; c++)
if (cli_stream.send_n (c, 1) == -1)
ACE_ERROR ((LM_ERROR, ACE_TEXT ("(%P|%t) %p\n"), ACE_TEXT ("send_n")));
// Explicitly close the writer-side of the connection.
if (cli_stream.close_writer () == -1)
ACE_ERROR ((LM_ERROR, ACE_TEXT ("(%P|%t) %p\n"), ACE_TEXT ("close_writer")));
char buf[1];
// Wait for handshake with server.
if (cli_stream.recv_n (buf, 1) != 1)
ACE_ERROR ((LM_ERROR, ACE_TEXT ("(%P|%t) %p\n"), ACE_TEXT ("recv_n")));
// Close the connection completely.
if (cli_stream.close () == -1)
ACE_ERROR ((LM_ERROR, ACE_TEXT ("(%P|%t) %p\n"), ACE_TEXT ("close")));
return 0;
}
示例7: process
int logClient::process(ACE_CString* s){
ACE_SOCK_Stream logger;
ACE_SOCK_Connector connector;
ACE_INET_Addr addr(9876, "127.0.0.1");
if(connector.connect(logger, addr) == -1){
ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%p \n"), ACE_TEXT("open")), -1);
}
ACE_Log_Record record(LM_DEBUG,
ACE_OS::time ((time_t *) 0),
ACE_OS::getpid());
record.msg_data(s.c_str());
const size_t max_payload_size =
4
+ 8
+ 4
+ 4
+ ACE_Log_Record::MAXLOGMSGLEN
+ ACE_CDR::MAX_ALIGNMENT;
ACE_OutputCDR payload(max_payload_size);
payload<< record;
ACE_CDR::ULong length =
ACE_Utils::truncate_cast<ACE_CDR::ULong> (payload.total_length());
ACE_OutputCDR header (ACE_CDR::MAX_ALIGNMENT + 8);
header << ACE_OutputCDR::from_boolean (ACE_CDR_BYTE_ORDER);
header << ACE_CDR::ULong(length);
iovec iov[2];
iov[0].iov_base = header.begin() -> rd_ptr();
iov[0].iov_len = 8;
iov[1].iov_base = payload.begin() -> rd_ptr();
iov[1].iov_len = length;
if (logger.sendv_n(iov, 2) == -1)
ACE_ERROR_RETURN((LM_ERROR,"%p\n","send"), -1);
/*
*/
ACE_Message_Block* header_p;
auto_ptr<ACE_Message_Block> header(header_p);
ACE_CDR::mb_align(header.get());
ACE_Message_Block* payload_p;
ssize_t count = logger.recv_n(header->wr_ptr(),8);
switch(count){
default:
case -1:
case 0:
case 8:
break;
}
header->wr_ptr(8);
}
示例8: server_addr
int connection::connect(char *hostname_opt_port, int tcp_nodelay, int sockbufsiz) {
if(!hostname_opt_port) return 1;
char *hostname_with_port;
// Check to see if portnumber is specified in the hostnameport
// If not, append :80
if(!ACE_OS::strchr(hostname_opt_port,':')) {
hostname_with_port = new char[ACE_OS::strlen(hostname_opt_port) + 3];
ACE_OS::sprintf(hostname_with_port, "%s:%d", hostname_opt_port, 80);
}
else {
hostname_with_port = hostname_opt_port;
}
// Beyond this point, hostname_with_port is of the form hostname:port
ACE_INET_Addr server_addr(hostname_with_port);
// Connect to server
ACE_SOCK_Connector con;
if(con.connect(stream_, server_addr) == -1) {
ACE_OS::perror("ACE_SOCK_Connector::connect");
return 1;
}
// tcp_nodelay processing.
// turn off weird ack things
if(tcp_nodelay) {
struct protoent *p = ACE_OS::getprotobyname ("tcp");
int one = 1;
if (p && stream_.set_option (p->p_proto,
TCP_NODELAY,
(char *)& one,
sizeof (one)))
{
ACE_OS::perror("tcp_nodelay");
return 1;
}
}
if(sockbufsiz)
if (stream_.set_option (SOL_SOCKET,
SO_RCVBUF,
(char *) &sockbufsiz,
sizeof sockbufsiz) == -1)
{
ACE_OS::perror("socket_queue_size");
return 1;
}
return 0;
}
示例9: ACE_TMAIN
int
ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
ACE_LOG_MSG->open (argv[0]);
parse_args (argc, argv);
// Default is to ask the server for ``help.''
static char buf[BUFSIZ] = "help\n";
int n;
ACE_SOCK_Stream sc;
ACE_SOCK_Connector con;
if (con.connect (sc,
ACE_INET_Addr (port_number,
host_name)) == -1)
ACE_ERROR_RETURN ((LM_ERROR,
"%p\n%a",
"connect",
1),
-1);
if (remote_reconfigure)
// Remotely instruct the server to reconfigure itself.
ACE_OS::strcpy (buf, "reconfigure\n");
// Send the command.
if (sc.send_n (buf,
ACE_OS::strlen (buf) + 1) == -1)
ACE_ERROR_RETURN ((LM_ERROR,
"%p\n%a",
"send",
1), -1);
// Next, read the response.
while ((n = sc.recv (buf,
sizeof buf)) > 0)
if (ACE_OS::write (ACE_STDOUT,
buf,
n) != n)
ACE_ERROR_RETURN ((LM_ERROR,
"%p\n%a",
"write",
1),
-1);
if (sc.close () == -1)
ACE_ERROR_RETURN ((LM_ERROR,
"%p\n%a",
"close",
1),
-1);
return 0;
}
示例10: open
int Client::open(const char *server, u_short port)
{
ACE_SOCK_Connector connector;
ACE_INET_Addr addr(port, server);
if(connector.connect(*this, addr) == -1)
{
ACE_ERROR_RETURN((LM_ERROR, "%p\n", "open"), -1);
}
initialized_ = 1;
return 0;
}
示例11: main
int
main (int argc, char *argv[])
{
#if !defined (ACE_LACKS_ACE_IOSTREAM)
const char *server_host = argc > 1 ? argv[1] : ACE_DEFAULT_SERVER_HOST;
u_short server_port = argc > 2 ? ACE_OS::atoi (argv[2]) : ACE_DEFAULT_SERVER_PORT;
ACE_IOStream<ACE_SOCK_Stream> server;
ACE_SOCK_Connector connector;
ACE_INET_Addr addr (server_port,
server_host);
if (connector.connect (server, addr) == -1)
ACE_ERROR_RETURN ((LM_ERROR,
"%p\n",
"open"),
-1);
// Buffer up some things to send to the server.
server << "1 2.3 testing" << endl;
int i;
float f;
#if defined (ACE_HAS_STRING_CLASS)
ACE_IOStream_String s1;
ACE_IOStream_String s2;
server >> s1 >> i >> f >> s2;
cerr << "Server said:\n\t";
cerr << s1 << " ";
cerr << i << " ";
cerr << f << " ";
cerr << s2 << endl;
#else
server >> i >> f;
cerr << "(" << ACE_OS::getpid () << ") Server sent:\n\t";
cerr << "(" << i << ") ";
cerr << "(" << f << ")" << endl;
#endif /* ACE_HAS_STRING_CLASS */
if (server.close () == -1)
ACE_ERROR_RETURN ((LM_ERROR,
"%p\n",
"close"),
-1);
#else
ACE_UNUSED_ARG (argc);
ACE_UNUSED_ARG (argv);
ACE_ERROR ((LM_ERROR, "ACE_IOSTREAM not supported on this platform\n"));
#endif /* !ACE_LACKS_ACE_IOSTREAM */
return 0;
}
示例12: ACE_ERROR_RETURN
int
Sender::open (const ACE_TCHAR *host,
u_short port)
{
// Initialize stuff
// Open input file (in OVERLAPPED mode)
this->input_file_ =
ACE_OS::open (file, GENERIC_READ | FILE_FLAG_OVERLAPPED);
if (this->input_file_ == ACE_INVALID_HANDLE)
ACE_ERROR_RETURN ((LM_ERROR,
"%p\n",
"ACE_OS::open"), -1);
// Find file size
this->file_size_ =
ACE_OS::filesize (this->input_file_);
// Connect to remote host
ACE_INET_Addr address (port, host);
ACE_SOCK_Connector connector;
if (connector.connect (this->stream_,
address) == -1)
ACE_ERROR_RETURN ((LM_ERROR,
"%p\n",
"ACE_SOCK_Connector::connect"),
-1);
// Open ACE_Asynch_Write_Stream
if (this->ws_.open (*this) == -1)
ACE_ERROR_RETURN ((LM_ERROR,
"%p\n",
"ACE_Asynch_Write_Stream::open"),
-1);
// Open ACE_Asynch_Read_File
if (this->rf_.open (*this, this->input_file_) == -1)
ACE_ERROR_RETURN ((LM_ERROR,
"%p\n",
"ACE_Asynch_Read_File::open"),
-1);
// Start an asynchronous transmit file
if (this->transmit_file () == -1)
return -1;
// Start an asynchronous read file
if (this->initiate_read_file () == -1)
return -1;
return 0;
}
示例13: ACE_DEBUG
int
Scavenger_Task::svc(void)
{
this->the_barrier_->wait ();
ACE_DEBUG ((LM_DEBUG, "(%P|%t) Starting scavenger thread\n"));
ACE_SOCK_Stream stream;
{
ACE_INET_Addr remote_sap (this->endpoint_);
ACE_SOCK_Connector connector;
if (connector.connect(stream, remote_sap) == -1)
{
ACE_ERROR((LM_ERROR, "Cannot connect to <%s>\n", endpoint_));
return -1;
}
}
for (;;)
{
ACE_Time_Value period (0, this->period_in_usecs_);
ACE_OS::sleep (period);
{
ACE_GUARD_RETURN (TAO_SYNCH_MUTEX, ace_mon, this->mutex_, -1);
if (this->stopped_)
break;
}
ACE_hrtime_t start = ACE_OS::gethrtime ();
ssize_t n = stream.send_n(&start, sizeof(start));
if (n == 0 || n == -1)
break;
ACE_hrtime_t end;
n = stream.recv(&end, sizeof(end));
if (n == 0 || n == -1)
break;
if (start != end)
{
ACE_ERROR((LM_ERROR,
"Mismatched response from <%s>\n", endpoint_));
break;
}
}
stream.close();
ACE_DEBUG ((LM_DEBUG, "(%P|%t) Finishing scavenger thread\n"));
return 0;
}
示例14: open
bool open()
{
ACE_SOCK_Connector connector;
ACE_INET_Addr addr(80,"127.0.0.1");
ACE_Time_Value timeout(5,0);
if(connector.connect(peer,addr,&timeout) != 0)
{
cout<<"connecetd fail"<<endl;
return false;
}
ACE_Reactor::instance()->register_handler(this,ACE_Event_Handler::READ_MASK);
cout<<"connecetd "<<endl;
return true;
}
示例15: worker
static ACE_THR_FUNC_RETURN
worker (void *)
{
ACE_OS::sleep (3);
const ACE_TCHAR *msg = ACE_TEXT ("Message from Connection worker");
ACE_TCHAR buf [BUFSIZ];
buf[0] = static_cast<ACE_TCHAR> ((ACE_OS::strlen (msg) + 1));
ACE_OS::strcpy (&buf[1], msg);
ACE_INET_Addr addr (rendezvous);
ACE_DEBUG((LM_DEBUG,
"(%t) Spawning %d client threads...\n",
cli_thrno));
int grp = ACE_Thread_Manager::instance ()->spawn_n (cli_thrno,
&cli_worker,
buf);
ACE_TEST_ASSERT (grp != -1);
ACE_Thread_Manager::instance ()->wait_grp (grp);
ACE_DEBUG ((LM_DEBUG,
"(%t) Client threads done; shutting down...\n"));
ACE_SOCK_Stream stream;
ACE_SOCK_Connector connect;
if (connect.connect (stream, addr) == -1)
ACE_ERROR ((LM_ERROR,
ACE_TEXT ("(%t) %p Error while connecting\n"),
ACE_TEXT ("connect")));
const ACE_TCHAR *sbuf = ACE_TEXT ("\011shutdown");
ACE_DEBUG ((LM_DEBUG,
"shutdown stream handle = %x\n",
stream.get_handle ()));
if (stream.send_n (sbuf, (ACE_OS::strlen (sbuf) + 1) * sizeof (ACE_TCHAR)) == -1)
ACE_ERROR ((LM_ERROR,
ACE_TEXT ("(%t) %p\n"),
ACE_TEXT ("send_n")));
ACE_DEBUG ((LM_DEBUG,
"Sent message of length = %d\n",
ACE_OS::strlen (sbuf)));
stream.close ();
return 0;
}