LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 736|回复: 1

问一个socket问题

[复制链接]
发表于 2004-7-13 15:10:49 | 显示全部楼层 |阅读模式
sock结构里有个rcvbuf,应该是指接收缓冲区的大小,另外sock结构下还有一个receive_queue接收队列,队列中的每个数据结构sk_buff就载运着一个到达的报文.
我的问题是队列中的sk_buff数据结构的多少是受什么限制,是rcvbuf大小的限制吗?
为什么我要提这个问题呢?我的一个程序,在接收UDP报文的时候,可能由于来不及取走socket队列中的UDP报文,部分UDP报文被后续的UDP报文冲掉,造成数据丢失.想增加接收队列的数量减少数据丢失.
谢谢!
发表于 2004-7-15 13:32:03 | 显示全部楼层
you can add rcvbuf to queue more skb,  but please note sysctl_rmem_max,  your value cannot over it.

sock.c

                case SO_RCVBUF:
                        /* Don't error on this BSD doesn't and if you think
                           about it this is right. Otherwise apps have to
                           play 'guess the biggest size' games. RCVBUF/SNDBUF
                           are treated in BSD as hints */
                          
                        if (val > sysctl_rmem_max)
                                val = sysctl_rmem_max;

                        sk->sk_userlocks |= SOCK_RCVBUF_LOCK;
                        /* FIXME: is this lower bound the right one? */
                        if ((val * 2) < SOCK_MIN_RCVBUF)
                                sk->sk_rcvbuf = SOCK_MIN_RCVBUF;
                        else
                                sk->sk_rcvbuf = val * 2;
                        break;



sock.h
static inline int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
{
        int err = 0;
        int skb_len;

        /* Cast skb->rcvbuf to unsigned... It's pointless, but reduces
           number of warnings when compiling with -W --ANK
         */
        if (atomic_read(&sk->sk_rmem_alloc) + skb->truesize >=
            (unsigned)sk->sk_rcvbuf) {
                err = -ENOMEM;
                goto out;
        }

.......................
         // adjust sk_rmem_alloc
        skb_set_owner_r(skb, sk);
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表