套接字:如何知道数据的发送时间 [英] sockets: How to know when your data is sent

查看:89
本文介绍了套接字:如何知道数据的发送时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,


我在通过拨号连接发送带有套接字的数据时遇到问题

连接。当我使用send函数时,它会很高兴地一次性发送一个兆字节以上的

缓冲区。但是当然,数据仍然是网络缓冲区中的
...意思是你不能断开一段时间

(但是多久......)。问题是,我怎么知道它什么时候完成?

有没有办法在真正发送数据时收到通知?


我尝试使用setsockopt和SO_SNDBUF来减少发送缓冲区大小,

认为数据实际上会以较小的增量发送,

而不是将整个内容放在缓冲区中把它拿出来我的

手......没有运气。这一切都有效,请注意,但是当数据真的不在我的电脑上时,我仍然无能为力。


我只是按照Python套接字操作方法中的示例进行操作。这里是发送功能的



def mysend(msg):

totalsent = 0

而totalsent< MSGLEN:

sent = self.sock.send(msg [totalsent:])

如果发送== 0:

引发RuntimeError,\\ \\\

套接字连接损坏

totalsent = totalsent +发送


有什么我想念的,或者有更好的方法吗?


谢谢,

-Marc

Hello,

I''m having a problem with sending data with sockets over a dial-up
connection. When I use the send function, it will happily send a
buffer of a megabyte and more in one shot. But of course, the data is
still in the network buffer... Meaning you can''t disconnect for awhile
(but for how long...). The problem is, how can I know when it''s done?
Is there a way to be notified when the data has truly been sent?

I tried using setsockopt and SO_SNDBUF to reduce the send buffer size,
thinking that the data would actually send in smaller increments,
instead of putting the whole thing in a buffer and taking it out of my
hands... No luck. It all works, mind you, but I''m left clueless as to
when the data is really off my computer!

I''m just following the example in the Python sockets How-To. Here''s
the send function:

def mysend(msg):
totalsent = 0
while totalsent < MSGLEN:
sent = self.sock.send(msg[totalsent:])
if sent == 0:
raise RuntimeError, \\
"socket connection broken"
totalsent = totalsent + sent

Is there something I''m missing, or is there a better way to do this?

Thanks,
-Marc

推荐答案

2004-11-09,Marc Ederis< me ***** @ hotmail.com>写道:
On 2004-11-09, Marc Ederis <me*****@hotmail.com> wrote:
我在使用套接字通过
拨号连接发送数据时遇到问题。当我使用send函数时,它会一次性地发送一个兆字节以上的缓冲区。但是当然,数据仍然在网络缓冲区中...意思
你不能断开一段时间(但是多久......)。
问题是,我怎么知道它什么时候完成?有没有办法在数据真正发送时收到通知?


您使用的操作系统是什么?


在Linux下,没有办法说出来。 IIRC,也没有办法在BSD下告诉
。我实际上曾经写过一些内核模式代码

一次提供一个ioctl()我可以从

用户空间调用,以找出我写入的数据的时间插座

实际上已发送。

有什么我想念的,或者有更好的方法吗?
I''m having a problem with sending data with sockets over a
dial-up connection. When I use the send function, it will
happily send a buffer of a megabyte and more in one shot. But
of course, the data is still in the network buffer... Meaning
you can''t disconnect for awhile (but for how long...). The
problem is, how can I know when it''s done? Is there a way to
be notified when the data has truly been sent?
What OS are you using?

Under Linux, there is no way to tell. IIRC, there''s no way to
tell under BSD either. I actually wrote some kernel mode code
once upon a time to provide an ioctl() that I could call from
user space to find out when the data I had written to a socket
was actually sent.
Is there something I''m missing, or is there a better way to do
this?




告诉数据已发送的方法是使用

应用程序级协议来确认数据传输器。


-

格兰特爱德华兹格兰特哇!请记住,在2039年,在MOUSSE& PASTA只需

处方即可获得
visi.com !!



The way to tell that data has been sent is to use an
application-level protocol that acknowleges the data transferr.

--
Grant Edwards grante Yow! Remember, in 2039,
at MOUSSE & PASTA will
visi.com be available ONLY by
prescription!!


Grant Edwards< gr ** **@visi.com>写道:
Grant Edwards <gr****@visi.com> wrote:
2004-11-09,Marc Ederis< me ***** @ hotmail.com>写道:
On 2004-11-09, Marc Ederis <me*****@hotmail.com> wrote:
当我使用send函数时,它会很快地发送一个兆字节以上的缓冲区。但是当然,数据仍在网络缓冲区中......
问题是,我怎么知道它什么时候完成?在Linux下,没有办法说出来。 IIRC,也没有办法告诉BSD。我实际上曾经写过一些内核模式代码,以便提供一个ioctl(),我可以从
用户空间调用,以找出我写入套接字的数据是什么时候实际上是发送。
When I use the send function, it will
happily send a buffer of a megabyte and more in one shot. But
of course, the data is still in the network buffer...
[ ... ] The
problem is, how can I know when it''s done?Under Linux, there is no way to tell. IIRC, there''s no way to
tell under BSD either. I actually wrote some kernel mode code
once upon a time to provide an ioctl() that I could call from
user space to find out when the data I had written to a socket
was actually sent.




我可能会在这里找不到问题的关键,但是在发送TCP_NODELAY以保证发送时不会是
()在最后一次ACK返回之前不会返回

?如果你没有使用TCP:

告诉数据已被发送的方法是使用
应用程序级协议来确认数据传输器。



I may well be missing the point of the problem here, but wouldn''t
just turning TCP_NODELAY on guarantee that send() won''t return
until the last ACK has returned? And if you''re not using TCP:
The way to tell that data has been sent is to use an
application-level protocol that acknowleges the data transferr.

<如果你关心可靠性,那么
适用于黑桃。


-

\S - si *** @ chiark.greenend.org.uk - http://www.chaos.org.uk/~sion/

___ | 坦率地说,我对这种或那种企鹅没有任何感情

\ X / | --Arthur C. Clarke

她的怒吼女演员是什么?ddre heafdes b?ce bump bump bump



applies in spades if you care about reliability.

--
\S -- si***@chiark.greenend.org.uk -- http://www.chaos.org.uk/~sion/
___ | "Frankly I have no feelings towards penguins one way or the other"
\X/ | -- Arthur C. Clarke
her nu becomet se bera eadward ofdun hl?ddre heafdes b?ce bump bump bump


2004-11 -09,Sion Arrowsmith< si *** @ chiark.greenend.org.uk>写道:
On 2004-11-09, Sion Arrowsmith <si***@chiark.greenend.org.uk> wrote:
当我使用send函数时,它会愉快地发送一个兆字节的缓冲区更多的是一次性。但是当然,数据仍然在网络缓冲区...... [...]问题是,我怎么知道它何时完成?
在Linux下,没有办法说出来。 IIRC,也没有办法告诉BSD。我实际上曾经写过一些内核模式代码,以便提供一个ioctl(),我可以从
用户空间调用,以找出我写入套接字的数据是什么时候实际上是发送。
When I use the send function, it will happily send a buffer of
a megabyte and more in one shot. But of course, the data is
still in the network buffer... [ ... ] The problem is, how
can I know when it''s done?
Under Linux, there is no way to tell. IIRC, there''s no way to
tell under BSD either. I actually wrote some kernel mode code
once upon a time to provide an ioctl() that I could call from
user space to find out when the data I had written to a socket
was actually sent.



我可能在这里错过了问题的重点,但是不会只是转向TCP_NODELAY以保证send()不会返回
直到最后一个ACK返回?



I may well be missing the point of the problem here, but wouldn''t
just turning TCP_NODELAY on guarantee that send() won''t return
until the last ACK has returned?




Nope。数据复制到

内核空间缓冲区后立即发送返回。 TCP_NODELAY对此没有影响。它只会改变堆栈的行为,因为它从那个

缓冲区获取数据并将其置于线路上。最终,TCP窗口

将填满,并且在tx缓冲区将填满之后,

之后,send将阻止。没有实际的方法来预测TCP窗口或tx缓冲区的大小。

还有一种实用的方法来确定数据量还有等待被激活的
(除非你想做内核

黑客攻击)。

如果你没有使用TCP:



Nope. Send returns as soon as the the data is copied to a a
kernel-space buffer. TCP_NODELAY has no effect on that. It
only changes the stack''s behavior as it''s taking data from that
buffer and putting it on the wire. Eventually, the TCP window
will fill up, and after than the tx buffer will fill up, and
after that, send will block. There''s no practical way to
predict the size of either the TCP window or the tx buffer.
There''s also no practical way to determine how much data is
still waiting to be acked (unless you want to do kernel
hacking).
And if you''re not using TCP:

告诉数据已被发送的方法是使用
应用程序级协议来确认数据传输器。
The way to tell that data has been sent is to use an
application-level protocol that acknowleges the data transferr.


如果你关心可靠性,则应用于黑桃。



applies in spades if you care about reliability.




不幸的是,许多编写网络应用程序的人(以及

协议)会产生各种各样的奇怪的假设,有人

最后跳过箍,试图解决问题,这些假设结果是错误的。 :/


-

Grant Edwards grante哇!我想知道我是否应该把自己放在ESCROW中来获得
!!

visi.com



Unfortunately, many people who write network applications (and
protocols) make all sorts of bizarre assumptions, and somebody
ends up jumping through hoops later to try to fix things when
those assumptions turn out to be wrong. :/

--
Grant Edwards grante Yow! I wonder if I should
at put myself in ESCROW!!
visi.com


这篇关于套接字:如何知道数据的发送时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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