TCP预分支服务器,接受周围的线程锁定 [英] tcp preforked server, thread locking around accept

查看:46
本文介绍了TCP预分支服务器,接受周围的线程锁定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

要为tcp预分支服务器找到一个c程序,线程锁定并接受解释?

were to find a c-program for the tcp preforked server, thread locking around accept with explanation?

推荐答案

这里是如何查找"这样的程序:

学习一些使用TCP的线程和网络,编写代码并尝试对其进行测试和调试.基本上,服务器端需要两个附加线程:一个用于侦听和接受新连接,一个用于使用可用连接从网络流中读取/写入网络流,以及一些套接字对象的集合,每个套接字对象代表一个远程套接字.您将需要使用线程同步原语来互锁对线程之间共享的套接字对象的访问.

我建议使用对套接字API的阻塞调用.另外,您需要在客户端上处理非正常的断开连接.为此,处理网络异常并从客户端的远程套接字集合中删除断开的套接字;再次使用线程同步原语,同时考虑到另一个线程正在使用相同的集合.

当您编写此类代码并遇到可以明确表述的问题时,请向CodeProject提出问题-我们很乐意为您提供帮助.

—SA
Here is how to "find" such program:

Learn some threading and networking with TCP, write the code and try to test and debug it. Basically, you will need two additional threads on the server side: one for listening and accepting new connections, one for reading/writing from/to network streams using available connections and some collection of socket objects each representing a remote socket. You will need to use thread synchronization primitives to interlock access to the socket objects shared between threads.

I would recommend to use blocking calls to the socket API. Also, you need to handle non-graceful disconnections on the client side. For this purpose, handle network exceptions and remove disconnected socket from the clients'' remote socket collection; again, using thread synchronization primitives, taking into account that the other thread is using the same collection.

When you write such code and face some problems which you can clearly formulate, ask CodeProject a question — we will gladly try to help you.

—SA


这篇关于TCP预分支服务器,接受周围的线程锁定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆