|
> Can anybody compare or contrast reasons for using write() or send() when > outputting to a socket? For me, it seems clearer to use send() in > general for sockets; but I have a possibility of outputting either to a > socket or an IFS streamfile. By using write(), the switch is fairly > easy. send() only works with sockets. It has the additional capability of specifying a descriptor flag in the 4th argument. For example, maybe you wanted to use non-blocking on just this call: send(fd: ptr_to_data: size_of_data: O_NONBLOCK) Write() lacks this capabilty, but has the advantage that it can be used with files as well as sockets. (and, you could always use fcntl() to set flags if you need to) > > Do the two APIs exist simply because that's how Unix evolved or is there > a clear difference? > It's just how Unix evolved. I believe that write() actually calls send() under the covers if the descriptor is a socket. And calls some other internal routine if it's a file. At any rate, if your intent is to write something that can be used with either sockets or files, go ahead and use write(), it won't cause any problems.
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.