⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 async_full_duplex.shtml

📁 mfc资源大全包含MFC编程各个方面的源码
💻 SHTML
字号:
<HTML>
<HEAD>
   <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
   <META NAME="Author" CONTENT="Rob Manderson">
   <TITLE>Internet - Asynchronous full-duplex connection class</TITLE>
</HEAD>
<body background="../fancyhome/back.gif" bgcolor="#FFFFFF" link="#B50029" vlink="#8E2323" alink="#FF0000">
<table WIDTH="100%">
<tr WIDTH="100%">
<td align=center><!--#exec cgi="/cgi/ads.cgi"--><td>
</tr>
</table>


<CENTER><H3><FONT COLOR="#AOAO99">Asynchronous full-duplex connection class</FONT></H3></CENTER>
<HR>


<P>This article was contributed by <A HREF="mailto:pbarvinko@yahoo.com">Paul Barvinko</A>.

<P>CInOutConnection is a class that encapsulates Client/Server connection node. It works in asynchronous full-duplex 
mode. After initialization it creates four threads: receiving, sending, working and service threads. First two are 
obvious, working thread waits for a message to be posted into input queue and then processes it and service thread 
could break connection on inactivity timeout or could be used for performing idle periodic tasks. 

<P>For keeping input and output queues in multithreaded environment I created CMessageQueue, which is simply 
wrapper under <vector> class from STL. The main difference is that before inserting or removing messages from the 
queue one should call CMessageQueue::BlockQueue() and then CMessageQueue::UnBlockQueue() in order to get 
exclusive access to the queue. For single message it could be done via CMessageQueue::GetFirstMessage() or 
CMessageQueue::AddSingleMessage() functions. To determine if there are messages in the queue one should call 
CMessageQueue::IsQueueFull(). 

<P>Class termination.

<P>To initiate connection termination, function CInOutConnection::SetTerminate() should be called. To check if it抯 
time to terminate, application could call CInOutConnection::Terminate() function. 

<P>Message exchange.

<P>To be independent of network providers class exposes two virtual functions: cioReceiveMessage(int* Error, int* 
length) and cioSendMessage(void* msg, int msg_size). They need to be overwritten in derived class for work with 
specific network providers. Depending on result of these functions network connection could be considered as 
broken and shutdown could be initiated.

<P>After message was successfully received it will be stick into input queue. Working thread, that checks for messages 
in input queue will be triggered automatically and will extract message from queue for processing. Currently there 
are three ways of message processing:

<P>1. Application can register callback function within the class and this function will be called for every incoming 
message. Callback function is defined like this:
typedef void (InOutCallbackFunc)(void* param), where param is pointer to 搕his

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -