Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

²ÉÓÃ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


Ïà¹ØÎĵµ£º

C/C++Êý×éÃûÓëÖ¸ÕëÇø±ðÉîÈë̽Ë÷

ÒýÑÔ
¡¡¡¡Ö¸ÕëÊÇC/C++ÓïÑÔµÄÌØÉ«£¬¶øÊý×éÃûÓëÖ¸ÕëÓÐÌ«¶àµÄÏàËÆ£¬ÉõÖÁºÜ¶àʱºò£¬Êý×éÃû¿ÉÒÔ×÷ΪָÕëʹÓá£ÓÚÊǺõ£¬ºÜ¶à³ÌÐòÉè¼ÆÕ߾ͱ»¸ãºýÍ¿ÁË¡£¶øÐí¶àµÄ´óѧÀÏʦ£¬ËûÃÇÔÚCÓïÑԵĽÌѧ¹ý³ÌÖÐÒ²´íÎóµÃ¸øѧÉú½²½â£º"Êý×éÃû¾ÍÊÇÖ¸Õë"¡£ºÜÐÒÔË£¬ÎҵĴóѧÀÏʦ¾ÍÊÇÆäÖÐÖ®Ò»¡£Ê±ÖÁ½ñÈÕ£¬ÎÒÈÕ¸´Ò»ÈյؽøÐÐ×ÅC/C++ÏîÄ¿µÄ¿ª·¢£¬¶øÉí±ß» ......

C/C++³ÌÐòԱӦƸ³£¼ûÃæÊÔÌâÉîÈëÆÊÎö

ת×Ô£ºhttp://dev.yesky.com/471/2306471.shtml
1.ÒýÑÔ
¡¡¡¡±¾ÎĵÄд×÷Ä¿µÄ²¢²»ÔÚÓÚÌṩC/C++³ÌÐòÔ±ÇóÖ°ÃæÊÔÖ¸µ¼£¬¶øÖ¼ÔÚ´Ó¼¼ÊõÉÏ·ÖÎöÃæÊÔÌâµÄÄÚº­¡£ÎÄÖеĴó¶àÊýÃæÊÔÌâÀ´×Ô¸÷´óÂÛ̳£¬²¿·ÖÊÔÌâ½â´ðÒ²²Î¿¼ÁËÍøÓѵÄÒâ¼û¡£
¡¡¡¡Ðí¶àÃæÊÔÌâ¿´ËƼòµ¥£¬È´ÐèÒªÉîºñµÄ»ù±¾¹¦²ÅÄܸø³öÍêÃÀµÄ½â´ð¡£ÆóÒµÒªÇóÃæÊÔÕßдһ¸ö×î¼òµ¥µÄst ......

c»ñµÃÎļþ´óС

 1.MFCÖеķ½·¨£º(C++)
CFileStatus status;
CFile::GetStatus("D:\\test.txt",status);
long lSizeOfFile;
lSizeOfFile = status.m_size;
lSizeOfFileµÄÖµ¾ÍÊÇD:\\test.txtÎļþµÄ´óС
2.±ê×¼C»ñµÃÎļþ´óСµÄ5ÖÖ·½·¨
(×¢Ò⣺"__FILE__"Ö¸µÄÊǵ±Ç°Îļþ£¬Äã¿ÉÒÔ¸ÄΪÓÐЧ·¾¶µÄÄ¿±êÎļþ£¬±ÈÈç"D:\\test.txt"£©
#i ......

extern "C" Ïê½â

 extern "C" Ïê½â
ÔÚC++ÖУ¬ÎªÁËÖ§³ÖÖØÔØ»úÖÆ£¬ÔÚ±àÒëÉú³É»ã±à´úÂëʱ£¬º¯ÊýµÄÃû×ÖÒª¼ÓÈ뺯ÊýµÄ²ÎÊýÀàÐÍ»òÕß·µ»ØÖµÀàÐ͵ÈÐÅÏ¢
ÔÚCÖУ¬ÒòûÓÐÖØÔØ»úÖÆ£¬±àÒëºóµÄ´úÂëÖ»ÊǼòµ¥µÄº¯ÊýÃû×Ö¶øÒÑ£¬²»¼ÓÈëÆäËûµÄÐÅÏ¢ 
1. ²»¼ÓÈëextern "C"
testexternc.cpp
int mytest(void)
{
int a=10,b=20;
int c=a+b;
ret ......

c/c++Ç¿ÖÆÀàÐÍת»»

 Q:ʲôÊÇC·ç¸ñת»»£¿Ê²Ã´ÊÇstatic_cast, dynamic_cast ÒÔ¼° reinterpret_cast£¿Çø±ðÊÇʲô£¿ÎªÊ²Ã´Òª×¢Ò⣿
A:ת»»µÄº¬ÒåÊÇͨ¹ý¸Ä±äÒ»¸ö±äÁ¿µÄÀàÐÍΪ±ðµÄÀàÐÍ´Ó¶ø¸Ä±ä¸Ã±äÁ¿µÄ±íʾ·½Ê½¡£ÎªÁËÀàÐÍת»»Ò»¸ö¼òµ¥¶ÔÏóΪÁíÒ»¸ö¶ÔÏóÄã»áʹÓô«Í³µÄÀàÐÍת»»²Ù×÷·û¡£±ÈÈ磬ΪÁËת»»Ò»¸öÀàÐÍΪdouboleµÄ¸¡µãÊýµÄÖ¸Õëµ½ÕûÐÍ£º ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ