【发布时间】:2019-10-14 04:35:49
【问题描述】:
请注意,这个问题专门针对 Ada 语言和 Ada 的“g-socket”API
我在本地打开了一个 Socket 并正在监听传入的连接。连接被接受,我可以通过读取和写入附加到远程套接字的 Stream 对象来建立连接上的一些连贯的数据传输。
问题:
当 Stream 附加到 TCP Socket 时,是否每次调用通用流 'Write 过程都会导致立即发送数据包?
示例 A:
-- two separate `'Write` calls always seems to generate two packets of 1 byte each
U8'Write (Comms, Number_Of_Security_Types);
U8'Write (Comms, Security_Type_None);
示例 B:
-- One `'Write` call that happens to send the same data formatted as a 16 bit value is sent as a single packet.
U16'Write (Comms,
(U16 (Number_Of_Security_Types) * 16#100#) +
U16 (Security_Type_None)
);
示例 C:
-- This is a complex record with a further record nested within it.
-- its `'Write` callback is implemented as a series of many sequential `Integer'Write` calls...
Server_Init'Write (Comms, Server_Init_Rec);
示例 A 和 C 导致 Wireshark 检测到格式错误的数据包,但示例 B 创建了一个精心设计的数据包,没有任何问题。
这种行为似乎是确定性的,但我找不到任何关于 'Write 的连贯文档 --> 流 --> 关于如何以及何时分派数据包的套接字安排。
【问题讨论】:
-
根据此链接,www2.adacore.com/gap-static/GNAT_Book/html/rts/… 我认为发生的情况取决于底层操作系统
-
question 不同,但答案相同。