锘??xml version="1.0" encoding="utf-8" standalone="yes"?>狠狠久久综合伊人不卡,久久久久久亚洲精品不卡 ,久久精品国产99国产精偷http://www.shnenglu.com/robinson119/category/4148.htmlUNIX/LINUX;ACE;SNMP;C++zh-cnSat, 24 May 2008 16:25:26 GMTSat, 24 May 2008 16:25:26 GMT60銆愯瘧銆慉CE Reactor 鐨勮璁″拰浣跨敤http://www.shnenglu.com/robinson119/archive/2007/08/03/29265.html瀹濇潐瀹濇潐Fri, 03 Aug 2007 04:42:00 GMThttp://www.shnenglu.com/robinson119/archive/2007/08/03/29265.htmlhttp://www.shnenglu.com/robinson119/comments/29265.htmlhttp://www.shnenglu.com/robinson119/archive/2007/08/03/29265.html#Feedback0http://www.shnenglu.com/robinson119/comments/commentRss/29265.htmlhttp://www.shnenglu.com/robinson119/services/trackbacks/29265.html1 浠嬬粛

姝ゆ枃鎻忚堪浜嗙粍鎴怉CE妗嗘灦鐨凴eactor妯″紡鐨勮璁″拰鎵ц銆俁eactor璐熻矗澶勭悊鐢變竴涓垨澶氫釜client騫跺彂鐨勪紶閫掔粰涓涓簲鐢ㄧ▼搴忕殑鏈嶅姟璇鋒眰銆傚簲鐢ㄧ▼搴忕殑姣忎釜鏈嶅姟鐢變竴涓垎紱葷殑event handler錛堜簨浠跺彞鏌勶級鎵ц錛宔vent handler鍖呮嫭涓涓垨澶氫釜榪涚▼鐨勬湇鍔″櫒鐗規畩璇鋒眰鐨勬柟娉曘?/p>

       姝ゆ枃鎻忚堪鐨凴eactor妯″紡鐨勬墽琛岋紝event handler鍒嗗彂鏄敱ACE_Reactor瀹炵幇鐨勩侫CE_Reactor緇撳悎I/O浜嬩歡鐨勫垎紱誨櫒錛屼互鍙婂叾浠栫被鍨嬬殑鏃墮棿錛屾瘮濡倀imers鍜宻ignals銆侫CE_Reactor鐨勬牳蹇冨疄鐜版槸鍩轟簬鍚屾浜嬩歡鍒嗙錛屾瘮濡俿elect鎴栬匴aitForMultipleObjects銆傚綋鍒嗙鍣ㄦ寚紺烘寚瀹氱殑浜嬩歡鍙戠敓浜嗭紝ACE_Reactor浼氳嚜鍔ㄥ垎鍙戦鍏堟敞鍐岀殑浜嬩歡鍙ユ焺鐨勬柟娉曘傛敞鍐岀殑event handler鏂規硶浼氬畬鎴愬簲鐢ㄧ▼搴忓搴旇姹備簨浠剁殑鏈嶅姟銆?/p>

       鏈枃緇勭粐濡備笅錛氱浜岀珷鎻忚堪ACE_Reactor妗嗘灦涓昏鐗規э紱絎笁绔犲ぇ鑷翠粙緇岮CE_Reactor瀹炵幇鐨凮O錛堥潰鍚戝璞★級璁捐錛涚鍥涚珷涓句簡鏈嶅姟鍣ㄧ瀹炵幇鐨勪緥瀛愶紝鐢ㄤ互璇佹槑ACE_Reactor鎬庢牱綆鍖栧茍鍙戠殑錛屽熀浜庝簨浠剁殑緗戠粶搴旂敤紼嬪簭鐨勫彂灞曪紱絎簲绔犳弿榪板綋浣跨敤ACE_Reactor寮鍙戝熀浜庝簨浠剁殑搴旂敤紼嬪簭鐨勮璁¤鍒欙紱絎叚绔犳槸緇撴潫璇?/p>

2 ACE_Reactor鐨勭壒鎬?/p>

ACE_Reactor鎻愪緵OO鐨勪簨浠跺垎紱繪満鍒跺拰娑堟伅鍒嗗彂妗嗘灦錛屽畠綆鍖栧熀浜庝簨浠剁殑搴旂敤紼嬪簭鐨勫紑鍙戙備互涓嬬壒鎬ф槸錛?/p>

OO鐨勪簨浠跺垎紱誨拰娑堟伅鍒嗗彂鎺ュ彛錛?/p>

浣跨敤ACE_Reactor鐨勫簲鐢ㄧ▼搴忎笉鐩存帴璋冪敤搴曞眰OS錛堟搷浣滅郴緇燂級鐨勪簨浠跺垎紱籄PI鍑芥暟銆傛瘮濡俿elect鎴朩aitForMultipleObjects銆備粬浠戶鎵緼CE Event Handler鍩虹被騫跺垱寤轟簡鍏蜂綋鐨別vent handlers銆傝繖涓被鐢ㄧ壒瀹氱殑铏氭嫙鍑芥暟澶勭悊涓嶅悓綾誨瀷鐨勪簨浠訛紝姣斿I/O浜嬩歡錛宼imer浜嬩歡錛宻ignals錛堜俊鍙烽噺鏈哄埗錛夛紝鍜屽悓姝ヤ簨浠躲?/p>

搴旂敤紼嬪簭鐢≧eactor妗嗘灦鍒涘緩鍏蜂綋鐨別vent handler錛屽茍娉ㄥ唽浠栦滑銆傜壒鎬?鏄劇ず浜咥CE Reactor.鐨勫叧閿粍浠躲傝繖涓壒鎬ф弿榪版墽琛屾棩瀛愭湇鍔$殑浜嬩歡鍙ユ焺錛岃繖涓湪絎洓绔犺榪般?br>



瀹濇潐 2007-08-03 12:42 鍙戣〃璇勮
]]>
[鍘焆ACE嫻?-鍒濆ACEhttp://www.shnenglu.com/robinson119/archive/2007/07/25/28745.html瀹濇潐瀹濇潐Wed, 25 Jul 2007 02:57:00 GMThttp://www.shnenglu.com/robinson119/archive/2007/07/25/28745.htmlhttp://www.shnenglu.com/robinson119/comments/28745.htmlhttp://www.shnenglu.com/robinson119/archive/2007/07/25/28745.html#Feedback2http://www.shnenglu.com/robinson119/comments/commentRss/28745.htmlhttp://www.shnenglu.com/robinson119/services/trackbacks/28745.html      ACE涓殑嫻佸寘瑁呮彁渚涢潰鍚戣繛鎺ョ殑閫氫俊銆傛祦鏁版嵁浼犺緭鍖呰綾誨寘鎷珹CE_SOCK_Stream鍜孉CE_LSOCK_Stream錛屽畠浠垎鍒寘瑁匱CP/IP鍜孶NIX鍩焥ocket鍗忚鏁版嵁浼犺緭鍔熻兘銆傝繛鎺ュ緩绔嬬被鍖呮嫭閽堝TCP/IP鐨凙CE_SOCK_Connector鍜孉CE_SOCK_Acceptor錛屼互鍙婇拡瀵筓NIX鍩焥ocket鐨凙CE_LSOCK_Connector鍜孉CE_LSOCK_Acceptor銆?br>      Acceptor綾葷敤浜庤鍔ㄥ湴鎺ュ彈榪炴帴錛堜嬌鐢˙SD accept()璋冪敤錛夛紝鑰孋onnector綾葷敤浜庝富鍔ㄥ湴寤虹珛榪炴帴錛堜嬌鐢˙SD connect()璋冪敤錛夈?br>      涓嬮潰鐨勪緥瀛愭紨紺烘帴鏀跺櫒鍜岃繛鎺ュ櫒鏄庢牱鐢ㄤ簬寤虹珛榪炴帴鐨勩傝榪炴帴闅忓悗灝嗙敤浜庝嬌鐢ㄦ祦鏁版嵁浼犺緭綾繪潵浼犺緭鏁版嵁銆?/p>

server绔唬鐮侊細
// 鐜VC6.0+ACE5.4.2
// proj:ACE stream server
// date:07-7-24
// robin
//

#include "stdafx.h"

#include "ace/Log_Msg.h"
#include "ace/Time_Value.h"
#include "ace/OS.h"


#include "ace/SOCK_Acceptor.h"
#include "ace/SOCK_Stream.h"

#define SIZE_DATA 18
#define SIZE_BUF 1024
#define NO_ITERATIONS 5

class Server
{
public:
 Server (int port) : server_addr_(port),peer_acceptor_(server_addr_)
 {
  data_buf_ = new char[SIZE_BUF];
 }

 //Handle the connection once it has been established. Here the
 //connection is handled by reading SIZE_DATA amount of data from the
 //remote and then closing the connection stream down.

 int handle_connection()
 {
  // Read data from client
  for(int i=0;i<NO_ITERATIONS;i++)
  {
   int byte_count=0;
   if( (byte_count = new_stream_.recv_n(data_buf_, SIZE_DATA, 0) ) == -1 )
    ACE_ERROR ((LM_ERROR, "%p\n", "Error in recv"));
   else
   {
    data_buf_[byte_count]=0;
    ACE_DEBUG((LM_DEBUG,"Server received %s \n",data_buf_));
   }
  }

  // Close new endpoint
  if (new_stream_.close () == -1)
   ACE_ERROR ((LM_ERROR, "%p\n", "close"));
  return 0;
 }


 //Use the acceptor component peer_acceptor_ to accept the connection
 //into the underlying stream new_stream_. After the connection has been
 //established call the handle_connection() method.
 
 int accept_connections ()
 {
  if (peer_acceptor_.get_local_addr (server_addr_) == -1)
   ACE_ERROR_RETURN ((LM_ERROR,"%p\n","Error in get_local_addr"),1);
  ACE_DEBUG ((LM_DEBUG,"Starting server at port %d\n",
   server_addr_.get_port_number ()));
  
  // Performs the iterative server activities.

  while(1)
  {
   ACE_Time_Value timeout (ACE_DEFAULT_TIMEOUT);
   if (peer_acceptor_.accept(new_stream_, &client_addr_, &timeout)== -1)
   {
    ACE_ERROR ((LM_ERROR, "%p\n", "accept"));
    continue;
   }
   else
   {
    ACE_DEBUG((LM_DEBUG,
     "Connection established with remote %s:%d\n",
     client_addr_.get_host_name(),client_addr_.get_port_number()));

    //Handle the connection
    handle_connection();
   }
  }
 }

private:
 char *data_buf_;
 ACE_INET_Addr server_addr_;
 ACE_INET_Addr client_addr_;
 ACE_SOCK_Acceptor peer_acceptor_;
 ACE_SOCK_Stream new_stream_;
};


int main (int argc, char *argv[])
{
 if(argc<2)
 {
  ACE_ERROR((LM_ERROR,"Usage %s <port_num>", argv[0]));
  ACE_OS::exit(1);
 }

// char *ip;
// ip = new char[strlen("192.168.1.160")];
// Server server(ACE_OS::atoi(ip));  //argv[1])

 Server server(ACE_OS::atoi(argv[1]));
 server.accept_connections();
 return 0;
}

client绔細
// proj:ACE stream client
// client
// date:7-24
// robin

#include "stdafx.h"

//******additional*******//
#include "ace/Log_Msg.h"  //ACE_ERROR ACE_DEBUG
#include "ace/Time_Value.h"  // ACE_Time_Value
#include "ace/OS.h"    // ACE_OS::atoi exit
//******additional*******//

#include "ace/SOCK_Connector.h"
#include "ace/INET_Addr.h"

#define SIZE_BUF 128
#define NO_ITERATIONS 5


class Client
{
public:
 Client(char *hostname, int port):remote_addr_(port,hostname)
 {
  data_buf_="Hello from Client";
 }

 //Uses a connector component `connector_’ to connect to a
 //remote machine and pass the connection into a stream
 //component client_stream_
 int connect_to_server()
 {
  // Initiate blocking connection with server.
  ACE_DEBUG ((LM_DEBUG, "(%P|%t) Starting connect to %s:%d\n",
   remote_addr_.get_host_name(),remote_addr_.get_port_number()));
  if (connector_.connect (client_stream_, remote_addr_) == -1)
   ACE_ERROR_RETURN ((LM_ERROR,"(%P|%t) %p\n","connection failed"),-1);
  else
   ACE_DEBUG ((LM_DEBUG,"(%P|%t) connected to %s\n",
   remote_addr_.get_host_name ()));
  return 0;
 }


 //Uses a stream component to send data to the remote host.
 int send_to_server()
 {
  // Send data to server
  for(int i=0;i<NO_ITERATIONS; i++)
  {
   if (client_stream_.send_n (data_buf_,
    ACE_OS::strlen(data_buf_)+1, 0) == -1)
   {
    ACE_ERROR_RETURN ((LM_ERROR,"(%P|%t) %p\n","send_n"),0);
    break;
   }
  }
  //Close down the connection
  close();
 }

 //Close down the connection properly.
 int close()
 {
  if (client_stream_.close () == -1)
   ACE_ERROR_RETURN ((LM_ERROR,"(%P|%t) %p\n","close"),-1);
  else
   return 0;
 }
private:
 ACE_SOCK_Stream client_stream_;
 ACE_INET_Addr remote_addr_;
 ACE_SOCK_Connector connector_;
 char *data_buf_;
};


int main(int argc, char* argv[])
{
 if(argc<3)
 {
  ACE_DEBUG((LM_DEBUG,"Usage %s <hostname> <port_number>\n", argv[0]));
  ACE_OS::exit(1);
 }

 Client client(argv[1],ACE_OS::atoi(argv[2]));
 client.connect_to_server();
 client.send_to_server();
 return 0;
}


榪愯緇撴灉錛?br>cmd閲屽埌exe鐩綍涓嬶紝鍏堝惎鍔ㄦ湇鍔$server.exe 192.168.1.160
濡傚浘1錛?br>
姝e湪杞絳夊緟銆?br>
鍐嶅埌client鏈嶅姟绔紝鍚屾牱鐨勬柟娉?br>榪愯鍛戒護琛屽弬鏁版牸寮?client.exe 192.168.1.160 192
 瑙f瀽錛欰CE_DEBUG((LM_DEBUG,"Usage %s <hostname> <port_number>\n", argv[0]));
         鍛戒護琛屽弬鏁頒負 <hostname><port> = <192.168.1.160><192>
         绔彛鏄敱鍥?鐨勭浜岃鏄劇ず錛屼笉鏄嚜宸辮瀹氱殑銆?br>濡傚浘2錛?br>

鍙槸鐓ф惉涔︿笂鐨勪緥瀛愶紝鍚庨潰鎵撶畻鑷繁鍒嗘瀽涓涓嬨?/span>

瀹濇潐 2007-07-25 10:57 鍙戣〃璇勮
]]>
亚洲国产精品无码久久一线| 香蕉久久夜色精品升级完成| 国产91久久综合| 久久精品一区二区影院| 久久人人爽人人爽人人片AV麻烦| 久久久久久国产精品美女| 狠狠88综合久久久久综合网| 久久噜噜电影你懂的| 色综合久久88色综合天天 | 欧美丰满熟妇BBB久久久| 国产精品日韩欧美久久综合| 久久精品无码一区二区WWW| 国产精品一久久香蕉产线看| 久久久久亚洲精品无码网址| 精品久久久久中文字幕日本| 天天做夜夜做久久做狠狠| 久久精品国产99久久无毒不卡| 久久国产成人| 91久久精品无码一区二区毛片| 久久毛片一区二区| 久久亚洲天堂| 久久精品国产一区二区| 热99re久久国超精品首页| 精品熟女少妇a∨免费久久| 久久香综合精品久久伊人| 久久这里只有精品视频99| 久久精品国产99国产精品澳门 | 久久国产精品免费一区| 人妻无码久久一区二区三区免费| 午夜精品久久久久久久无码| 精品久久久久一区二区三区| 99久久人人爽亚洲精品美女| 久久99国产精品久久久| 久久精品国产只有精品2020| 2021久久国自产拍精品| 久久久久亚洲AV无码网站| 日日躁夜夜躁狠狠久久AV| 亚洲中文字幕无码久久精品1| 精品国产99久久久久久麻豆| 亚洲综合伊人久久大杳蕉| 精品熟女少妇AV免费久久|