Re: [PATCH] socket.7: Add info about SO_PEEK_OFF option

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



>> Hope this makes things more clear.
> 
> Yep, that helps considerably. I've extensively reworked your text,
> adding quite a bit more detail. Could you check the text below please?

Yup, this is exactly what I was trying to say! Thanks!

> Cheers,
> 
> Michael
> 
>   SO_PEEK_OFF (since Linux 3.4)
>          This option, which is currently supported only for unix(7)
>          sockets,  sets  the  value  of  the  "peek offset" for the
>          recv(2) system call when used with MSG_PEEK flag.
> 
>          When this option is set to a negative value (it is set  to
>          -1 for all new sockets), traditional behavior is provided:
>          recv(2) with the MSG_PEEK flag will  peek  data  from  the
>          front of the queue.
> 
>          When the option is set to a value greater than or equal to
>          zero, then the next peek at data queued in the socket will
>          occur  at  the  byte offset specified by the option value.
>          At the same time, the "peek offset" will be incremented by
>          the  number  of  bytes that were peeked from the queue, so
>          that a subsequent peek will return the next  data  in  the
>          queue.i
> 
>          If  data is removed from the front of the queue via a call
>          to recv(2) (or similar) without  the  MSG_PEEK  flag,  the
>          "peek  offset"  will  be  decreased by the number of bytes
>          removed.  In  other  words,  receiving  data  without  the
>          MSG_PEEK  flag will cause the "peek offset" to be adjusted
>          to maintain the correct relative position  in  the  queued
>          data,  so  that  a  subsequent peek will retrieve the data
>          that would have been  retrieved  had  the  data  not  been
>          removed.
> 
>          For  datagram  sockets, if the "peek offset" points to the
>          middle of a packet, the data returned will be marked  with
>          the MSG_TRUNC flag.
> 
>          The  following  example  serves  to  illustrate the use of
>          SO_PEEK_OFF.  Suppose a stream socket  has  the  following
>          queued input data:
> 
>              aabbccddeeff
> 
>          The  following  sequence  of  recv(2) calls would have the
>          effect noted in the comments:
> 
>              int ov = 4;                  // Set peek offset to 4
>              setsockopt(fd, SOL_SOCKET, SO_PEEK_OFF, &ov, sizeof(ov));
> 
>              recv(fd, buf, 2, MSG_PEEK);  // Peeks "cc"; offset set to 6
>              recv(fd, buf, 2, MSG_PEEK);  // Peeks "dd"; offset set to 8
>              recv(fd, buf, 2, 0);         // Reads "aa"; offset set to 6
>              recv(fd, buf, 2, MSG_PEEK);  // Peeks "ee"; offset set to 8
> .
> 


--
To unsubscribe from this list: send the line "unsubscribe linux-man" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Kernel Documentation]     [Netdev]     [Linux Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux