本文整理汇总了C++中ACE_SOCK_Stream类的典型用法代码示例。如果您正苦于以下问题:C++ ACE_SOCK_Stream类的具体用法?C++ ACE_SOCK_Stream怎么用?C++ ACE_SOCK_Stream使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ACE_SOCK_Stream类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}
示例2: error
int
ACE_SOCK_Connector::shared_connect_start (ACE_SOCK_Stream &new_stream,
const ACE_Time_Value *timeout,
const ACE_Addr &local_sap)
{
ACE_TRACE ("ACE_SOCK_Connector::shared_connect_start");
if (local_sap != ACE_Addr::sap_any)
{
sockaddr *laddr = reinterpret_cast<sockaddr *> (local_sap.get_addr ());
int size = local_sap.get_size ();
if (ACE_OS::bind (new_stream.get_handle (),
laddr,
size) == -1)
{
// Save/restore errno.
ACE_Errno_Guard error (errno);
new_stream.close ();
return -1;
}
}
// Enable non-blocking, if required.
if (timeout != 0
&& new_stream.enable (ACE_NONBLOCK) == -1)
return -1;
else
return 0;
}
示例3: ACE_TMAIN
/*
fence: 1) send the heartbeat message to repo at regular basis. 1/1 minute, get back the messages,
calculate the digest, and send to localhost:9907
2)listens on localhost:9901, for the incoming raw inputs, calculate the digest, and send it to hub:10007
*/
int
ACE_TMAIN(int argc, ACE_TCHAR* argv[]){
ACE_SOCK_Acceptor _9901acceptor;
ACE_INET_Addr _9901addr(9901);
//create the acceptor
if(_9901acceptor.open(_9901addr,1)==-1){
ACE_ERROR_RETURN((LM_ERROR,
"%p\n","open"),1);
}else if(_9901acceptor.get_local_addr(_9901addr)== -1){
ACE_ERROR_RETURN((LM_ERROR,
"%p\n","get_local_addr"),1);
}
ACE_DEBUG((LM_INFO,
"(%P|%t) starting server at port %d\n",
_9901addr.get_port_number()));
// ACE_INET_Addr repo_addr(repo_port,repo_host.c_str());
ACE_SOCK_Connector con;
// ACE_SOCK_Stream cli_stream ;
ACE_Thread_Manager* mgr = ACE_Thread_Manager::instance();
// if(con.connect(cli_stream,repo_addr)==-1){
// ACE_ERROR_RETURN((LM_ERROR,
// "(%P|%t:%l) %p\n","connection failed"),0);
// }else{
// ACE_DEBUG((LM_DEBUG,
// "(%P|%t) connected to %s at port %d\n",repo_addr.get_host_name(),repo_addr.get_port_number()));
// }
/*connector side; do in a seperate thread;
*/
if(mgr->spawn(fetch_step2,
0,
THR_DETACHED) == -1){
ACE_ERROR ((LM_ERROR,
"(%P|%t) %p\n",
"spawn"));
}
/*
run the accept loop ;
*/
do{
ACE_SOCK_Stream stream;
if(_9901acceptor.accept(stream)== -1){
ACE_ERROR_RETURN((LM_ERROR,
"(%P|%t:%l) %p\n","accept failed"),0);
}else{
ACE_DEBUG((LM_DEBUG,
"(%P|%t:%l) connected to %s at port %d\n",_9901addr.get_host_name(),_9901addr.get_port_number()));
}
if(mgr->spawn(accept_step1,
reinterpret_cast<void *> (stream.get_handle()),
THR_DETACHED) == -1){
ACE_ERROR ((LM_ERROR,
"(%P|%t) %p\n",
"spawn"));
}
}while(true);
return 0;
}
示例4: PollData
void Collector::PollData()
{
ACE_SOCK_Stream peer;
ACE_SOCK_Connector connector;
try
{
if(TryToConnect(connector,peer))
{
std::ostringstream oss;
oss << "poll data form cluster: " << data_source_.name;
LOG4CXX_INFO(log_,oss.str());
char buf[T_SIZE] = "request";
if((peer.send(buf,sizeof(buf)))<=0)
throw "KSN POLLER COLLECTOR SEND REQUEST ERROR!!";
char* ch = new char[T_SIZE]();
if((peer.recv(ch,T_SIZE)<=0))
throw "KSN POLLER COLLECTOR RECV ERROR!!";
msg_ = new ACE_Message_Block(ch,sizeof(*ch));
sender_->putq(msg_);
}
else
{
std::ostringstream oss;
oss << "Can not poll data form " + data_source_.name;
LOG4CXX_WARN(log_,oss.str());
}
}
catch(const char* ch)
{
LOG4CXX_ERROR(log_,ch);
}
}
示例5: ACE_ASSERT
///////////////////////////////////////////////////////////////////////////
// <summary>
// This method writes data from the given buffer to the underlying stream.
// It can block or not, depending on the value of the blocking parameter.
// </summary>
//
// <param name = "buffer">
// The buffer that contains the data to be written.
// </param>
//
// <param name = "size">
// The size of the buffer in bytes of the buffer.
// </param>
//
// <param name = "blocking">
// True if the write request should block; false otherwise.
// </param>
//
// <param name = "bytesWritten">
// An out parameter that will contain the number of bytes that have been
// written to the stream.
// </param>
//
// <returns>
// Returns a MgStreamStatus value indicating the status of the operation.
// </returns>
MgStreamHelper::MgStreamStatus MgAceStreamHelper::WriteData(void* buffer,
size_t size, bool blocking, size_t* bytesWritten)
{
// Do not attempt writing zero byte to the socket as this could be problematic.
if (0 == size)
{
return MgStreamHelper::mssDone;
}
ACE_ASSERT( buffer && size > 0 );
MgStreamHelper::MgStreamStatus stat = MgStreamHelper::mssError;
// check parameters
if ( buffer && size > 0 )
{
// init out parameter
if ( bytesWritten != NULL )
*bytesWritten = 0;
ACE_SOCK_Stream stream;
stream.set_handle( m_handle );
ssize_t res = 0;
// On Linux, use MSG_NOSIGNAL to request not to send SIGPIPE on
// errors on stream oriented sockets when the other end breaks
// the connection. The EPIPE error is still returned.
// Note that neither trapping the SIGPIPE signal via an
// ACE_Event_Handler nor calling ACE_OS::signal(SIGPIPE, SIG_IGN)
// seems to work.
if ( blocking )
{
res = stream.send_n(buffer, size, MG_MSG_NOSIGNAL);
}
else
{
res = stream.send(buffer, size, MG_MSG_NOSIGNAL);
}
// check for failure
if ( res >= 0 )
{
// update out parameter
if ( bytesWritten != NULL )
*bytesWritten = res;
if ( res == (ssize_t)size )
{
stat = MgStreamHelper::mssDone;
}
else
{
stat = blocking ? MgStreamHelper::mssError : MgStreamHelper::mssNotDone;
}
}
}
return stat;
}
示例6: ACE_TMAIN
int
ACE_TMAIN(int argc, ACE_TCHAR* argv[]){
ACE_SOCK_Acceptor acceptor;
ACE_INET_Addr addr(10009);
if(acceptor.open(addr,1)){
ACE_ERROR_RETURN((LM_ERROR,
"%p\n", "open"),1);
}
else if(acceptor.get_local_addr(addr) == -1){
ACE_ERROR_RETURN((LM_ERROR,
"%p\n", "get_local_addr"),1);
}
ACE_DEBUG((LM_INFO,
"(%P|%t) starting server at port %d\n",addr.get_port_number()));
ACE_Thread_Manager* mgr = ACE_Thread_Manager::instance();
while(true){
ACE_SOCK_Stream stream;
if(acceptor.accept(stream) == -1){
ACE_ERROR((LM_ERROR,
"%p\n","accept"));
continue;
}else{
ACE_DEBUG((LM_DEBUG,
"(%P|%t) spawning one thread\n"));
handle_input(mgr, commu, stream.get_handle());
}
}
return 0;
}
示例7:
int
Synch_Thread_Pool_Task::svc (void)
{
// Creates a factory of HTTP_Handlers binding to synchronous I/O strategy
Synch_HTTP_Handler_Factory factory;
for (;;)
{
ACE_SOCK_Stream stream;
// Lock in this accept. When it returns, we have a connection.
if (this->acceptor_.accept (stream) == -1)
ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "HTTP_Acceptor::accept"), -1);
ACE_Message_Block *mb;
ACE_NEW_RETURN (mb,
ACE_Message_Block (HTTP_Handler::MAX_REQUEST_SIZE + 1),
-1);
// Create an HTTP Handler to handle this request
HTTP_Handler *handler = factory.create_http_handler ();
handler->open (stream.get_handle (), *mb);
// Handler is destroyed when the I/O puts the Handler into the
// done state.
mb->release ();
ACE_DEBUG ((LM_DEBUG,
" (%t) in Synch_Thread_Pool_Task::svc, recycling\n"));
}
ACE_NOTREACHED(return 0);
}
示例8:
void
JAWS_Synch_IO_No_Cache::send_message (const char *buffer, int length)
{
ACE_SOCK_Stream stream;
stream.set_handle (this->handle_);
stream.send_n (buffer, length);
}
示例9: handle
void
JAWS_Synch_IO::receive_file (const char *filename,
void *initial_data,
int initial_data_length,
int entire_length)
{
ACE_Filecache_Handle handle (ACE_TEXT_CHAR_TO_TCHAR (filename), entire_length);
int result = handle.error ();
if (result == ACE_Filecache_Handle::ACE_SUCCESS)
{
ACE_SOCK_Stream stream;
stream.set_handle (this->handle_);
int bytes_to_memcpy = ACE_MIN (entire_length, initial_data_length);
ACE_OS::memcpy (handle.address (), initial_data, bytes_to_memcpy);
int bytes_to_read = entire_length - bytes_to_memcpy;
int bytes = stream.recv_n ((char *) handle.address () + initial_data_length,
bytes_to_read);
if (bytes == bytes_to_read)
this->handler_->receive_file_complete ();
else
result = -1;
}
if (result != ACE_Filecache_Handle::ACE_SUCCESS)
this->handler_->receive_file_error (result);
}
示例10: handle
void
JAWS_Synch_IO::receive_file (JAWS_IO_Handler *ioh,
const char *filename,
void *initial_data,
unsigned int initial_data_length,
unsigned int entire_length)
{
ACE_Filecache_Handle handle (filename,
(int) entire_length);
int result = handle.error ();
if (result == ACE_Filecache_Handle::ACE_SUCCESS)
{
ACE_SOCK_Stream stream;
stream.set_handle (ioh->handle ());
int bytes_to_memcpy = ACE_MIN (entire_length, initial_data_length);
ACE_OS::memcpy (handle.address (), initial_data, bytes_to_memcpy);
int bytes_to_read = entire_length - bytes_to_memcpy;
int bytes = stream.recv_n ((char *)
handle.address () + initial_data_length,
bytes_to_read);
if (bytes == bytes_to_read)
ioh->receive_file_complete ();
else
result = -1;
}
if (result != ACE_Filecache_Handle::ACE_SUCCESS)
ioh->receive_file_error (result);
}
示例11: 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;
}
示例12: IsConnected
bool MgAceStreamHelper::IsConnected()
{
bool bConnected = true;
ACE_SOCK_Stream stream;
stream.set_handle( m_handle );
UINT8 dummy;
ACE_Time_Value val(0, 0);
ssize_t res = stream.recv_n(&dummy, 1, MSG_PEEK | MG_MSG_NOSIGNAL, &val);
if ( res < 0 )
{
// Error or timeout occured
#ifdef _WIN32
int error = ::WSAGetLastError(); // errno doesn't work correctly on Windows
bConnected = ( error == WSAEWOULDBLOCK || error == 0 );
#else
bConnected = ( errno == EWOULDBLOCK || errno == 0 || errno == ETIME );
#endif
}
else if (res == 0)
{
// No longer connected
bConnected = false;
}
return bConnected;
}
示例13: 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);
}
示例14: main
int main(int argc, char* argv[]){
if (argc > 1){
return 1;
}
cout << argv[0] << endl;
ACE_INET_Addr addr(1234, ACE_LOCALHOST);
ACE_SOCK_Stream stream;
ACE_SOCK_Acceptor acceptor;
int success = acceptor.open(addr, 1);
ACE_TCHAR addrStr[20];
if (success > 0) {
addr.addr_to_string(addrStr, 20);
}
//*
success = acceptor.accept(stream);
if (success < 0) {
cout << "Cannot accept" << endl;
return 1;
}
//*/
char buf[BUFSIZ];
int n;
char *msg = "You are connected";
stream.send_n(msg, strlen(msg));
stream.close();
/*
while (stream.recv(buf, BUFSIZ)) {
// _write(1, buf, n);
cout << buf << endl;
}
//*/
cout << endl << "Done" << endl;
return 0;
}
示例15: unmarshalledOctetServer
// thread function that serves the client for the UnMarshalled Octet
// test
static ACE_THR_FUNC_RETURN unmarshalledOctetServer (void *arg){
// unbundle the arguments
ArgStruct * args = reinterpret_cast<ArgStruct *> (arg);
ACE_SOCK_Stream * dataModeStream = args->stream;
ACE_CDR::ULong numIterations = args->numIters;
delete args;
// serve the client for numIterations synchronous invocations
do {
// READ A MESSAGE FROM THE CLIENT
size_t bt;
ACE_CDR::ULong msgBufSize=0;
// read the size of the buffer to follow
if ((dataModeStream->recv_n(&msgBufSize, ACE_CDR::LONG_SIZE, 0, &bt)) == -1)
ACE_ERROR_RETURN((LM_ERROR,
ACE_TEXT ("%p\n"),
ACE_TEXT ("recv_n")),
0);
msgBufSize = ACE_NTOHL(msgBufSize);
// allocate the buffer for the message payload
ACE_CDR::Octet * msgBuf = 0;
ACE_NEW_RETURN(msgBuf,
ACE_CDR::Octet[msgBufSize],
0);
// read the buffer
if ((dataModeStream->recv_n(msgBuf, msgBufSize, 0, &bt)) == -1)
ACE_ERROR_RETURN((LM_ERROR,
ACE_TEXT ("%p\n"),
ACE_TEXT ("recv_n")),
0);
// clean up the allocated buffer
delete[] msgBuf;
// SEND A REPLY TO THE CLIENT
// send back a 2 byte reply
ACE_CDR::Short reply;
if ((dataModeStream->send_n(&reply, ACE_CDR::SHORT_SIZE, 0, &bt)) == -1)
ACE_ERROR_RETURN((LM_ERROR,
ACE_TEXT ("%p\n"),
ACE_TEXT ("send_n")),
0);
} while (--numIterations);
// close and destroy the stream
dataModeStream->close();
delete dataModeStream;
return 0;
}