Subject: sendfile(2) and SCTP?

From: Craig Rodrigues <[email-masked]>
Date: Fri, 20 Feb 2004 16:39:22 -0500

Hi,

Can any of the SCTP implementors comment on
the compatibility of their SCTP stacks
and the sendfile() call?

This call exists on {Free,Open,Net}BSD, and Linux,
and maybe some other platforms which I don't know.

From the FreeBSD man page:

http://www.freebsd.org/cgi/man.cgi?query=sendfile&sektion=2

"The sendfile() system call sends a regular file specified by 
 descriptor fd out a stream socket specified by descriptor s."

This man page was probably written before SCTP implementations 
were around.  However, using sendfile() + SCTP seems useful,
so I wonder what implementations support it.

Thanks.

-- 
Craig Rodrigues        Distributed Systems and Logistics, Office 6/325A
[email-masked]       BBN Technologies
(617) 873-4725         Cambridge, MA

---

From: "Randall Stewart (cisco)" <[email-masked]>
Date: Fri, 20 Feb 2004 15:50:13 -0600

Craig:

Interesting ... I have never tried it.. nor have I looked
into how they actually do the mappings...

I will have to poke around and see :->

R

-- 
Randall R. Stewart
ITD - Transport Technologies
815-477-2127(o) or 815-342-5222(c)

---

From: "Brian F. G. Bidulock" <[email-masked]>
Date: Fri, 20 Feb 2004 15:22:19 -0700

Craig,

sendfile(2) in Linux is a system call.  The system call is implemented
with simple looping writes to the output file descriptor.  If the output
file (socket) supports the sendpage() file operation, full memory mapped
pages will be transferred.  If the output file descriptor does not
support the sendpage() file operation, simple write() file operations
will be used (internally) instead.

Linux NET4 TCP supports the sendpage() file operation.  OpenSS7 SCTP
does not yet support the sendpage() file operation, however, sendfile
will use the write() operation available instead.  Support for
sendpage() file operation is a TODO for the OpenSS7 SCTP stack.  Under
2.4 it requires the use of paged sk_buffs.  Neither TCP nor OpenSS7 SCTP
supports mmap on 2.4.  If mmap support were to be provided, the socket
could also act as the in_fd of the sendfile(2) call.

In general, on Linux, any socket supporting a write(2) operation should
be usable as the out_fd of a sendfile(2) call.  As any socket supporting
sendmsg(2) automatically supports write(2) and writev(2), sendfile(2)
should be usable on all connection oriented socket implementations,
regardless of protocol.

Because it supports the write(2)/writev(2) file operation, even the
OpenSS7 STREAMS implementation of SCTP supports sendfile(2).

I would be suprised to hear that any kernel implementation of SCTP does
not support sendfile(2).

Hope that helps.

--brian

-- 
Brian F. G. Bidulock    ¦ The reasonable man adapts himself to the ¦
[email-masked]    ¦ world; the unreasonable one persists in  ¦
http://www.openss7.org/ ¦ trying  to adapt the  world  to himself. ¦
                        ¦ Therefore  all  progress  depends on the ¦
                        ¦ unreasonable man. -- George Bernard Shaw ¦

---

From: "Randall Stewart (cisco)" <[email-masked]>
Date: Fri, 20 Feb 2004 17:02:55 -0600

Craig:

After a bit of code reading in FreeBSD it looks like
the zero-copy send would work with KAME-SCTP.

The sendfile() function takes care of reading/scheduling
in the pages right from the file-system into kernel memory.
A mbuf header is wrapped around this.. and then
the pru_send() of the protocol is called.

This does some minor checks (looking for MORE_TO_COME.. which
is NOT set by sendfile) and then calls the sctp_output function.
This will fragment the 4k block into MTU size pieces by creating
additional MBUF's to point into the aux buffers .. and then
send them out..

All zero copy..

Interesting :->

R