本文整理汇总了C++中ACE_SOCK_Stream::close_writer方法的典型用法代码示例。如果您正苦于以下问题:C++ ACE_SOCK_Stream::close_writer方法的具体用法?C++ ACE_SOCK_Stream::close_writer怎么用?C++ ACE_SOCK_Stream::close_writer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ACE_SOCK_Stream
的用法示例。
在下文中一共展示了ACE_SOCK_Stream::close_writer方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: addr
/*the repo function
talk to the repo.jg.org at a regular interval, 1 minute,
and send acknowledgement to repo.jg.org
*/
static ACE_THR_FUNC_RETURN
fetch_step2(void *){
ACE_INET_Addr addr(repo_port, repo_host.c_str());
ACE_SOCK_Connector con;
ACE_SOCK_Stream stream;
do{
if(con.connect(stream, addr) == -1){
ACE_ERROR_RETURN ((LM_ERROR,
"(%P|%t:%l) %p\n",
"connection failed"),
0);
}
else
ACE_DEBUG ((LM_DEBUG,
"(%P|%t:%l) connected to %s at port %d\n",
addr.get_host_name (),
addr.get_port_number ()));
ACE_CString hb = ACE_CString("^^hb->");
hb+=id+"$$";
ACE_DEBUG((LM_INFO,
"%l: %s\n", hb.c_str()));
stream.send(hb.c_str(),hb.length());
stream.close_writer();
ACE_DEBUG((LM_INFO,
"%l\n"));
char* buf = new char[128];
ACE_CString str;
do{
int bytes = stream.recv(buf,128);
if(bytes == -1 || bytes == 0){
break;
}
for(int i=0; i< bytes; i++){
str += buf[i];
}
}while(true);
delete[] buf;
stream.close();
ACE_CString acks = ACE_CString("^^");
int p1=2;
int p2= str.find("->",p1);
int p3 = str.find("->",p2);
int p4 = str.find("||",p3);
node *head=NULL, *tail=NULL;
while(p1 != -1 && p2 != -1 && p3 != -1){
ACE_CString* pqr = new ACE_CString(str.substr(p1, p2 - p1));
ACE_CString* v2 = new ACE_CString(str.substr(p2, p3 - p2));
ACE_CString txn_id = str.substr(p3, p4 - p3);
acks+="ack->"+txn_id+"||";
node* n = new node(pqr, v2);
if(head == NULL){
head = n;
tail = n;
}else{
tail->next = n;
tail = n;
}
}
acks+="$$";
// delete str;
if(con.connect(stream, addr) == -1){
ACE_ERROR_RETURN ((LM_ERROR,
"(%P|%t:%l) %p\n",
"connection failed"),
0);
}
else
ACE_DEBUG ((LM_DEBUG,
"(%P|%t:%l) connected to %s at port %d\n",
addr.get_host_name (),
addr.get_port_number ()));
//send out the acks
ACE_DEBUG((LM_INFO,
"(%P|%t:%l) %s\n",acks.c_str()));
stream.send(acks.c_str(),acks.length());
stream.close();
node* tmp=head;
// ACE_SOCK_Connector connector;
ACE_INET_Addr _9907addr(9907,"localhost");
//ACE_SOCK_Stream stream;
if(con.connect(stream, _9907addr) == -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",
_9907addr.get_host_name (),
_9907addr.get_port_number ()));
ACE_CString reply = ACE_CString("^^");
while(tmp!=NULL){
//.........这里部分代码省略.........
示例2: sa
int
ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
parse_args (argc, argv);
ACE_INET_Addr sa (port_number, host_name);
void *cp;
char buf[BUFSIZ];
int n;
ACE_SOCK_CODgram dc;
if (dc.open (sa, ACE_Addr::sap_any) == -1)
ACE_ERROR_RETURN ((LM_ERROR,
"%p\n",
"open"),
-1);
// First send the name of the file as a datagram.
iovec iov[2];
iov[0].iov_base = (char *) "filename: ";
iov[0].iov_len = 11;
iov[1].iov_base = (char *) file_name;
iov[1].iov_len = ACE_OS::strlen (file_name);
if (dc.send (iov, 2) == -1)
ACE_ERROR_RETURN ((LM_ERROR,
"%p\n",
"send"),
-1);
ACE_SOCK_Stream sc;
ACE_SOCK_Connector con;
if (con.connect (sc, sa) == -1)
ACE_ERROR_RETURN ((LM_ERROR,
"%p\n",
"connect"),
-1);
ACE_Mem_Map mmap (file_name);
if (mmap (cp) == -1)
ACE_ERROR_RETURN ((LM_ERROR,
"%p\n",
"mmap"),
-1);
// Next, send the file's contents.
if (sc.send_n (cp, mmap.size ()) == -1)
ACE_ERROR_RETURN ((LM_ERROR,
"%p\n",
"send_urg"),
-1);
if (sc.close_writer () == -1)
ACE_ERROR_RETURN ((LM_ERROR,
"%p\n",
"close_writer"),
-1);
if ((n = sc.recv_n (buf, sizeof buf)) == -1)
ACE_ERROR_RETURN ((LM_ERROR,
"%p\n",
"recv"),
-1);
else
ACE_OS::write (ACE_STDOUT, buf, n);
return 0;
}