问题描述
好的,起初我使用的是非阻塞套接字,但是当我尝试捕获来自多个用户的单个事件时,它很快变得混乱和不准确.如此之多,以至于我认为即使使用互斥锁,即使是多线程也是更好的选择.但是我有一个问题.在每个连接的每个线程中,应该在recv处阻塞并无限期等待,但是,那么,让我说我希望关闭服务器,并在recv中结束线程?反正有强迫recv立即返回吗?是否将套接字从另一个线程(中间recv)设置为非阻塞模式,可能导致它返回,还是必须在调用recv之前将其设置好?
okay, at first i was working with non-blocking sockets, but then when i was trying to catch individual events from multiple users, it quickly became cluttered and innaccurate. So much so, that i think even multithreading is a better alternative, just using mutexes. But i''ve got a problem. in each thread for each connection, it is supposed to block at recv and wait indefinately, but then, let''s say that i wish to shutdown the server, and end the thread mid recv? is there anyway to force recv to return immediately? does setting the socket to non-blocking mode from another thread, mid recv, maybe cause it to return or does it HAVE to be set before recv is called?
推荐答案
这篇关于用winsock线程并强制recv返回的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!