本文介绍了平行话费送/ recv的同一插座上是否有效?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


  1. 我们还可以从一个线程和recv发送从另一个同一插座上?

  2. 我们可以调用多个不同线程平行发送相同的插槽上?

我知道,一个好的设计应该避免这种情况,但我不清楚这些系统API将如何表现。我无法找到一个良好的文档也一样。

I know that a good design should avoid this, but I am not clear how these system APIs will behave. I am unable to find a good documentation also for the same.

在方向任何指针会有所帮助。

Any pointers in the direction will be helpful.

推荐答案

POSIX定义发送/ recv的是原子操作,所以假设你在谈论POSIX发送/ recv的话,是的,你可以同时从多个线程和东西给他们打电话会工作。

POSIX defines send/recv as atomic operations, so assuming you're talking about POSIX send/recv then yes, you can call them simultaneously from multiple threads and things will work.

这并不一定意味着他们会并行执行 - 在多的情况下发送,第二个可能会被阻塞,直到第一个结束。你可能不会注意到这么多,作为发送完成一旦​​其将数据输出到socket缓冲区。

This doesn't necessarily mean that they'll be executed in parallel -- in the case of multiple sends, the second will likely block until the first completes. You probably won't notice this much, as a send completes once its put its data into the socket buffer.

如果你使用SOCK_STREAM套接字,试图做的事情并行不太可能像发送有用/ recv的可能发送或接收消息,这意味着事情的一部分可以得到分手了。

If you're using SOCK_STREAM sockets, trying to do things a parallel is less likely to be useful as send/recv might send or receive only part of a message, which means things could get split up.

阻塞发送/ recv的上SOCK_STREAM套接字只阻塞,直到他们发送或recv至少1个字节,因此阻塞与非阻塞的区别是没有用的。

Blocking send/recv on SOCK_STREAM sockets only block until they send or recv at least 1 byte, so the difference between blocking and non-blocking is not useful.

这篇关于平行话费送/ recv的同一插座上是否有效?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-23 18:47