?? 52.htm
字號:
<HTML><HEAD><TITLE>CTerm非常精華下載</TITLE>
<META content="text/html; charset=gb2312" http-equiv=Content-Type></HEAD>
<BODY bgColor=#ffffff>
<TABLE border=0 cellPadding=0 cellSpacing=0 width=100% background=0044.jpg>
<BODY>
<TR>
<TD height=150 rowSpan=2 width="308" ><IMG alt=DDl_back.jpg height=129 width=300 src="DDl_back.jpg" ></TD>
<TD background=DDl_back2.jpg height=50 width="581" ><BIG><BIG><FONT face=黑體>
<P align=center >重拳出擊 一網打盡</FONT></BIG></BIG></P></TD></TR>
<TR>
<TD bgColor=#0099ff borderColor=#0099ff height=5 width="581"></TD></TR>
<TR>
<TD align=middle colSpan=2 height=100 vAlign=top width="891" ><BR>
<p align=center>[<a href="清華bbs網絡資源.htm">回到開始</a>][<a href="6.htm">上一層</a>][<a href="53.htm">下一篇</a>]
<hr><p align="left"><small>發信人: ghzhang (忽忽), 信區: Winsock <br>
<br>
我用VC5在WINDOWS95下編程,用CSOCKET類,因為SOCKET在發送數據時 <br>
占時間比較長,我想開另一個線程專門管發送,結果在主線程中創建的 <br>
SCOKET在該線程中沒辦法用(好象ASSERT有問題,主線程中保存著一些 <br>
SCOKET信息,而子線程沒有)。用子線程創建SOCKET又沒法用。 <br>
<br>
各位大俠誰做過,望不吝賜教,萬分感激。 <br>
<br>
<br>
<br>
發信人: rainland (雨田), 信區: Winsock <br>
<br>
【 在 ghzhang (忽忽) 的大作中提到: 】 <br>
: 我用VC5在WINDOWS95下編程,用CSOCKET類,因為SOCKET在發送數據時 <br>
why not use Berkerly socket? <br>
I once used it in writing a multi-threads program under WIN95, <br>
all goes well. <br>
<br>
: 占時間比較長,我想開另一個線程專門管發送,結果在主線程中創建的 <br>
: SCOKET在該線程中沒辦法用(好象ASSERT有問題,主線程中保存著一些 <br>
: SCOKET信息,而子線程沒有)。用子線程創建SOCKET又沒法用。 <br>
: 各位大俠誰做過,望不吝賜教,萬分感激。 <br>
<br>
<br>
<br>
<br>
發信人: xiangchao (不知所云), 信區: Winsock <br>
<br>
你最好該用CAsyncSocket <br>
【 在 ghzhang (忽忽) 的大作中提到: 】 <br>
: 我用VC5在WINDOWS95下編程,用CSOCKET類,因為SOCKET在發送數據時 <br>
: 占時間比較長,我想開另一個線程專門管發送,結果在主線程中創建的 <br>
: SCOKET在該線程中沒辦法用(好象ASSERT有問題,主線程中保存著一些 <br>
: SCOKET信息,而子線程沒有)。用子線程創建SOCKET又沒法用。 <br>
: 各位大俠誰做過,望不吝賜教,萬分感激。 <br>
<br>
<br>
<br>
<br>
發信人: lhg (心魔), 信區: Winsock <br>
<br>
【 在 ghzhang (忽忽) 的大作中提到: 】 <br>
: 我用VC5在WINDOWS95下編程,用CSOCKET類,因為SOCKET在發送數據時 <br>
: 占時間比較長,我想開另一個線程專門管發送,結果在主線程中創建的 <br>
為什么不在子線程中創建呢? <br>
<br>
: SCOKET在該線程中沒辦法用(好象ASSERT有問題,主線程中保存著一些 <br>
: SCOKET信息,而子線程沒有)。用子線程創建SOCKET又沒法用。 <br>
Why ? <br>
: 各位大俠誰做過,望不吝賜教,萬分感激。 <br>
<br>
<br>
<br>
<br>
發信人: rainland ( 雨田), 信區: Winsock <br>
<br>
【 在 mwgjh (蕭秋雨) 的大作中提到: 】 <br>
: In a multithreaded application, can more than one thread access <br>
: a single socket? <br>
: Yes. However, keep in mind that Winsock is not thread-safe. <br>
: For example, if one thread is interrupted by the operating <br>
: system's scheduler while executing a call to recv() and <br>
: another thread in the same program calls recv() on that same <br>
: socket before the first thread gets control again, <br>
: havoc will result.If you must let multiple threads access a <br>
: single socket, you need to carefully serialize the calls <br>
: that use it. Unfortunately, I cannot say for certain <br>
: how paranoid you need to be about this. At minimum, <br>
: you should ensure that no two threads can call <br>
: the same Winsock function on a given socket at the same time. <br>
: However, it may be necessary to completely serialize every <br>
: call that uses the socket, so that no two threads can use <br>
: the same socket at the same time for anything. <br>
<br>
答非所問吧?;) <br>
在一個線程中使用另一線成創建的SOCKET(berkerly style)是完全可以的, <br>
只是不能多個線程同時使用。 <br>
<br>
<br>
<br>
發信人: zhfeng (fenger), 信區: Winsock <br>
<br>
【 在 rainland (雨田) 的大作中提到: 】 <br>
: why not use Berkerly socket? <br>
: I once used it in writing a multi-threads program under WIN95, <br>
: all goes well. <br>
<br>
IN fact, use CSocket directly is not a good idea. The better way is to inheret <br>
a new class with CSocket as a base Class(public). Then reload the OnAccept() <br>
and OnReceive(). These func are callback style functions. Use this method, <br>
you will discard the ideea of multithread in socket. For detail, you can study <br>
the samples of chatter and chatServer(sample/mfc/....) <br>
<br>
<br>
<br>
發信人: yxy (田絲絲@小鷹夏日炎炎正好眠), 信區: Winsock <br>
<br>
【 在 zhfeng (fenger) 的大作中提到: 】 <br>
: IN fact, use CSocket directly is not a good idea. The better way is to inheret <br>
: a new class with CSocket as a base Class(public). Then reload the OnAccept() <br>
: and OnReceive(). These func are callback style functions. Use this method, <br>
: you will discard the ideea of multithread in socket. For detail, you can study <br>
: the samples of chatter and chatServer(sample/mfc/....) <br>
這是一個可行的方法,只通過動態生成新CSOCKET對象完成并發服務,但不知WINDOWS下 <br>
若是同時隨機的訪問很多文件,例如A線程或A SOCKET對象想讀文件1、3、4,而B想讀 <br>
6、3、2,這種情況如何解決文件不能同時打開的問題呢?WINDOWS提供的同步機制似乎 <br>
必須為每個臨界對象提供一個信號燈,但是要是有1000多個文件,豈不是要有1000多個 <br>
信號燈??沒有象UNIX中那樣文件局部加鎖,阻塞等待的機制。瘟95、瘟NT怎么實現類 <br>
似功能呢? <br>
<br>
<br>
<br>
</small><hr>
<p align="center">[<a href="清華bbs網絡資源.htm">回到開始</a>][<a href="6.htm">上一層</a>][<a href="53.htm">下一篇</a>]<p align="center" ><font face="黑體" size=5><big>網絡資源大全</big></font></p>
</table>
</body>
</html>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -