Unix Network Programming Episode 74

Exploring Head-of-Line Blocking

A stream in SCTP is not a stream of bytes (as in TCP), but a sequence of messages that is ordered within the association. These sub-ordered streams are used to avoid the head-of-line blocking found in TCP.

Head-of-line blocking occurs when a TCP segment is lost and a subsequent TCP segment arrives out of order. That subsequent segment is held until the first TCP segment is retransmitted and arrives at the receiver. Delaying delivery of the subsequent segment assures that the receiving application sees all data in the order in which the sending application sent it. This delay to achieve complete ordering is quite useful, but it has a downside. Assume that semantically independent messages are being sent over a single TCP connection.

复制代码
#include "unp.h"

void sctpstr_client_echoall(FILE *fp, int sock_fd, struct sockaddr *to, socklen_t tolen)
{
    struct sockaddr_in peeraddr;
    struct sctp_sndrcvinfo sri;
    char sendline[SCTP_MAXLINE], recvline[SCTP_MAXLINE];
    socklen_t len;
    int rd_sz, i, strsz;
    int msg_flags;

    bzero(sendline, sizeof(sendline));
    bzero(&sri, sizeof(sri));
    while(fgets(sendline,SCTP_MAXLINE-9, fp)!=NULL)
    {
        strsz=strlen(sendline);
        if(sendline[strsz-1]=='\n')
        {
            sendline[strsz-1]='\0';
            strsz--;
        }
        for(i=0;i<SERV_MAX_SCTP_STRM;i++)
        {
            snprintf(sendline+strsz, sizeof(sendline)-strsz,".msg. %d",i);
            Sctp_sendmsg(sock_fd, sendline, sizoef(sendline),to, tolen,0,0,i,0,0);
        }
        for(i=0;i<SERV_MAX_SCTP_STRM;i++)
        {
            len=sizeof(peeraddr);
            rd_sz=Sctp_recvmsg(sock_fd, recvline, sizeof(recvline), (SA *)&peeraddr, &len, &sri, &msg_flags);
            printf("From str:%d seq:%d (assoc: 0X%X) :", sri.sinfo_stream, sri.sinfo_ssn, (u_int)sri.sinfo_assoc_id);
            printf("%.*s\n", rd_sz,recvline);
        }
    }
}

sctp_strcliecho

复制代码
for(i=0;i<SERV_MAX_SCTP_STRM;i++)
{
    snprintf(sendline+strsz, sizeof(sendline)-strsz,".msg. %d",i);
    Sctp_sendmsg(sock_fd, sendline, sizoef(sendline),to, tolen,0,0,i,0,0);
    snprintf(sendline+strsz, sizeof(sendline)-strsz, ".msg.%d 2",i);
    Sctp_sendmsg(sock_fd, sendline, sizeof(sendline), to, tolen, 0,0,i,0,0);
}
for(i=0;i<SERV_MAX_SCTP_STRM;i++)
{
    len=sizeof(peeraddr);

sctp_strcliecho modifications

Controlling the Number of Streams

复制代码
if(argc==2)
    stream_increment=atoi(argv[1]);
sock_fd=Socket(AF_INET, SOCK_SEQPACKET, IPPROTO_SCTP);
bzero(&initm,sizeof(initm));
initm.sinit_num_ostreams=SERV_MORE_STRMS_SCTP;
Setsockopt(sock_fd, IPPROTO_SCTP, SCTP_INITMSG, &initm,sizeof(initm));

Requesting more streams in our server

相关推荐
DevOps前进四14 小时前
光模块与跳线
网络
蜡台14 小时前
AI Agent 架构终极教程:从原理分层、四大范式到生产级落地实战
网络·人工智能·架构
为思念酝酿的痛15 小时前
数据链路层--帧传输与链路控制
网络·网络协议·计算机网络·数据链路层
头发还在的女程序员15 小时前
【无标题】
网络·数据库·短剧小程序·短剧系统·海外短剧·短剧后台
Gauss松鼠会16 小时前
【GaussDB】破除gaussdb ugin索引支持中文模糊查询的迷思-字符序
java·运维·服务器·网络·数据库·gaussdb·经验总结
luiyarch16 小时前
汽车电子ISO 21448 SOTIF系列(第26期):未知危险场景的确认方法(下)——AI驱动的场景发现
网络·人工智能·安全·车载系统·汽车
砚凝霜16 小时前
【软考信息安全】第十六章 网络安全风险评估项目流程与应用
网络·安全·web安全
Mr_韩16 小时前
子网路由实战:无需公网 IP,异地直接访问家庭内网全部设备
运维·网络·物联网·nas
Bruce_Liuxiaowei16 小时前
内网“影子资产“:串口服务器安全盲区剖析
服务器·网络·安全·iot