📄 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 + -