²ÉÓÃC++µÄACE¿âʵÏÖµÄÒ»¸öͨÓõÄC/S¼Ü¹¹Í¨ÐųÌÐò
ACE×ÔÊÊÅäͨÐÅ»·¾³£¨ADAPTIVE Communication Environment£©ÊÇ¿ÉÒÔ×ÔÓÉʹÓᢿª·ÅÔ´ÂëµÄÃæÏò¶ÔÏó£¨OO£©¿ò¼Ü£¨Framework£©£¬ÔÚÆäÖÐʵÏÖÁËÐí¶àÓÃÓÚ²¢·¢Í¨ÐÅÈí¼þµÄºËÐÄģʽ¡£ACEÌṩÁËÒ»×é·á¸»µÄ¿É¸´ÓÃC++ Wrapper Facade£¨°ü×°Íâ¹Û£©ºÍ¿ò¼Ü×é¼þ£¬¿É¿çÔ½¶àÖÖƽ̨Íê³ÉͨÓõÄͨÐÅÈí¼þÈÎÎñ£¬ÆäÖаüÀ¨£ºÊ¼þ¶à··ÖÀëºÍʼþ´¦ÀíÆ÷·ÖÅÉ¡¢ÐźŴ¦Àí¡¢·þÎñ³õʼ»¯¡¢½ø³Ì¼äͨÐÅ¡¢¹²ÏíÄÚ´æ¹ÜÀí¡¢ÏûϢ·ÓÉ¡¢·Ö²¼Ê½·þÎñ¶¯Ì¬£¨ÖØ£©ÅäÖᢲ¢·¢Ö´ÐкÍͬ²½£¬µÈµÈ¡£
ACEµÄÄ¿±êÓû§ÊǸßÐÔÄܺÍʵʱͨÐÅ·þÎñºÍÓ¦ÓõĿª·¢Õß¡£Ëü¼ò»¯ÁËʹÓýø³Ì¼äͨÐÅ¡¢Ê¼þ¶à··ÖÀë¡¢ÏÔʽ¶¯Ì¬Á´½ÓºÍ²¢·¢µÄOOÍøÂçÓ¦ÓúͷþÎñµÄ¿ª·¢¡£´ËÍ⣬ͨ¹ý·þÎñÔÚÔËÐÐʱÓëÓ¦ÓõĶ¯Ì¬Á´½Ó£¬ACE»¹Ê¹ÏµÍ³µÄÅäÖúÍÖØÅäÖõÃÒÔ×Ô¶¯»¯¡£
ÎÒ×î½ü²ÉÓÃACEʵÏÖÁËÒ»¸öͨÓõÄC/S¼Ü¹¹Í¨ÐųÌÐò£¬¾ßÌåʵÏÖ¼òÊöÈçÏ£º
1£® ·þÎñÆ÷¶Ë£ºÒ»¸ö²ÉÓÃÁìµ¼Õß/¸úËæÕßÄ£Ð͵ÄÏ̳߳ز»¶ÏµØ½ÓÊÜ´Ó¶à¸ö¿Í»§¶Ë·¢À´µÄÏûÏ¢£¬²¢·ÅÈëÒ»¸öÏûÏ¢¶ÓÁУ¬È»ºóÓÖÓÐÒ»¸ö²ÉÓðëͬ²½/°ëÒ첽ģÐ͵ÄÏ̳߳ز»¶ÏµØ´ÓÕâ¸öÏûÏ¢¶ÓÁÐÖÐÈ¡³öÏûÏ¢½øÐд¦Àí¡£
·þÎñÆ÷¶Ë´úÂëÈçÏ£º£¨¹²10¸öÎļþ£©
ACE_Server.cpp
#include "ace/SOCK_Acceptor.h"
#include "ace/Acceptor.h"
#include "ace/Thread_Manager.h"
#include "ace/TP_Reactor.h"
#include "ace/Reactor.h"
#include "ace/INET_Addr.h"
#include "ace/OS.h"
#include "Request_Handler.h"
#include "Server.h"
#include "Constants.h"
using namespace ACE_Server;
int main(int argc, char *argv[])
{
ACE_TP_Reactor tp_reactor;
ACE_Reactor reactor(&tp_reactor, 1);
ACE_Reactor::instance(&reactor, 1);
ACE_Acceptor<Request_Handler, ACE_SOCK_ACCEPTOR> acceptor;
ACE_INET_Addr addr(SERVER_PORT_NUM);
if(acceptor.open(addr) == -1)
return -1;
Server server_tp;
server_tp.activate(THR_NEW_LWP | THR_JOINABLE, SERVER_THREAD_POOL_SIZE);
ACE_Thread_Manager::instance()->wait();
return 0;
}
Consta
Ïà¹ØÎĵµ£º
ʹÓÃKeil Cµ÷ÊÔijϵͳʱ»ýÀÛµÄһЩ¾Ñé
1¡¢ÔÚWindows2000ÏÂÃ棬ÎÒÃÇ¿ÉÒÔ°Ñ×ÖÌåÉèÖÃΪCourier£¬ÕâÑù¾Í¿ÉÒÔÏÔʾÕý³£¡£
2¡¢µ±Ê¹ÓÃÓÐƬÍâÄÚ´æµÄMCU£¨ÈçW77E58£¬ËüÓÐ1KƬÍâÄڴ棩µÄʱºò£¬¿Ï¶¨ÒªÉèÖñê־룬²¢ÇÒ±àÒ뷽ʽҪѡÔñ´óģʽ£¬·ñÔò»á³ö´í¡£
3¡¢µ±Ê¹ÓÃKeil C¸ú×Ù³ÌÐòÔËÐÐ״̬µÄʱºò£¬Òª°ÑÒýÆðWarningµÄÓï¾äÆÁ±Î£ ......
ÈçºÎѧϰCºÍC++²Å²»Ã£È»£¬²Å²»ÊÇÂÒѧ£¬ÏëÁËһϣ¬ÕâÀï¸ø³öÒ»¸ö×ܵĻظ´¡£
¡¡¡¡Ò»¼ÒÖ®ÑÔ£¬»¶ÓÅÄש¹þ¡£
¡¡¡¡1¡¢¿ÉÒÔ¿¼ÂÇÏÈѧϰC.
¡¡¡¡´ó¶àÊýʱºò£¬ÎÒÃÇѧϰÓïÑÔµÄÄ¿µÄ£¬²»ÊÇΪÁ˳ÉΪһ¸öÓïÑÔר¼Ò£¬¶øÊÇÏ£Íû³ÉΪһ¸ö½â¾öÎÊÌâµÄר¼Ò¡£×öÒ»¸öÓÐÓõijÌÐòÔ±£¬×öÒ»¸ö׬ǮµÄ³ÌÐòÔ±¡£ÎÒÃǵļÛÖµ£¬½«ÌåÏÖÔÚ¿Í»§¼ÛÖµÉÏ£¬¶ø²»ÊÇÓï ......
CµÄËÄÖÖ´æ´¢ÀàÏÞ¶¨·û£º
extern:Íⲿ±äÁ¿
static £º¾²Ì¬
register£º´æ´¢Æ÷
auto£º×Ô¶¯¡¡
¾²Ì¬¾Ö²¿±äÁ¿£º
´æ´¢ÇøºÍÈ«¾Ö±äÁ¿ÊÇÒ»ÑùµÄ¡£¾²Ì¬¾Ö²¿ºÍÈ«¾Ö±äÁ¿¼äµÄÖ÷ÒªÇø±ðÊÇ£º¾²Ì¬¾Ö²¿±äÁ¿½ö¶ÔËüÔÚÆäÖÐÉùÃ÷µÄ¿éÊÇ¿ÉÖªµÄ¡£
¾²Ì¬È«¾Ö±äÁ¿£º
¸æËß±àÒëÆ÷´´½¨Ò»¸ö½öÔÚÉùÃ÷ËüµÄÎļþÖпÉÖªµÄÈ«¾Ö±äÁ¿¡£ÕâÒâζ×Å£º¼´Ê¹±äÁ¿Ê ......
Ôø¾Åöµ½¹ýÈÃÄãÃԻ󲻽⡢ÀàËÆÓÚint * (* (*fp1) (int) ) [10];ÕâÑùµÄ±äÁ¿ÉùÃ÷Â𣿱¾ÎĽ«ÓÉÒ×µ½ÄÑ£¬Ò»²½Ò»²½½Ì»áÄãÈçºÎÀí½âÕâÖÖ¸´ÔÓµÄC/C++ÉùÃ÷¡£
¡¡¡¡ÎÒÃǽ«´ÓÿÌ춼ÄÜÅöµ½µÄ½Ï¼òµ¥µÄÉùÃ÷ÈëÊÖ£¬È»ºóÖð²½¼ÓÈëconstÐÞÊηûºÍtypedef£¬»¹Óк¯ÊýÖ¸Õ룬×îºó½éÉÜÒ»¸öÄܹ»ÈÃÄã׼ȷµØÀí½âÈκÎC/C++ÉùÃ÷µÄ&ld ......
Q:ʲôÊÇC·ç¸ñת»»£¿Ê²Ã´ÊÇstatic_cast, dynamic_cast ÒÔ¼° reinterpret_cast£¿Çø±ðÊÇʲô£¿ÎªÊ²Ã´Òª×¢Ò⣿
A:ת»»µÄº¬ÒåÊÇͨ¹ý¸Ä±äÒ»¸ö±äÁ¿µÄÀàÐÍΪ±ðµÄÀàÐÍ´Ó¶ø¸Ä±ä¸Ã±äÁ¿µÄ±íʾ·½Ê½¡£ÎªÁËÀàÐÍת»»Ò»¸ö¼òµ¥¶ÔÏóΪÁíÒ»¸ö¶ÔÏóÄã»áʹÓô«Í³µÄÀàÐÍת»»²Ù×÷·û¡£±ÈÈ磬ΪÁËת»»Ò»¸öÀàÐÍΪdouboleµÄ¸¡µãÊýµÄÖ¸Õëµ½ÕûÐÍ£º
......