This is the mail archive of the
ecos-patches@sources.redhat.com
mailing list for the eCos project.
IO/NET - fix getsockname, add iovec functions
- From: Gary Thomas <gthomas at ecoscentric dot com>
- To: eCos patches <ecos-patches at sources dot redhat dot com>
- Date: 03 Nov 2002 13:07:21 -0700
- Subject: IO/NET - fix getsockname, add iovec functions
Index: io/fileio/current/ChangeLog
===================================================================
RCS file: /misc/cvsfiles/ecos/packages/io/fileio/current/ChangeLog,v
retrieving revision 1.22
diff -u -5 -p -r1.22 ChangeLog
--- io/fileio/current/ChangeLog 9 Aug 2002 17:10:21 -0000 1.22
+++ io/fileio/current/ChangeLog 3 Nov 2002 18:55:43 -0000
@@ -1,5 +1,10 @@
+2002-11-03 Gary Thomas <gthomas@ecoscentric.com>
+
+ * src/io.cxx:
+ * cdl/fileio.cdl: Add readv()/writev() support.
+
2002-08-08 Nick Garnett <nickg@calivar.demon.co.uk>
* src/select.cxx (select): Changed mechanism for calculating
select timeout to avoid possible race conditions between this code
and the timer DSR.
Index: io/fileio/current/cdl/fileio.cdl
===================================================================
RCS file: /misc/cvsfiles/ecos/packages/io/fileio/current/cdl/fileio.cdl,v
retrieving revision 1.7
diff -u -5 -p -r1.7 fileio.cdl
--- io/fileio/current/cdl/fileio.cdl 29 May 2002 18:28:25 -0000 1.7
+++ io/fileio/current/cdl/fileio.cdl 3 Nov 2002 18:26:01 -0000
@@ -196,10 +196,25 @@ cdl_package CYGPKG_IO_FILEIO {
to indicate no dead inode caching should be
provided."
}
}
+ cdl_option CYGNUM_FILEIO_IOVEC_MAX {
+ display "Maximum size of iovec used by readv/writev"
+ flavor data
+ default_value 16
+ legal_values 1 to 9999999
+ description "This option controls the maximum size of the iovec
+ structure that can be used by readv()/writev(). This
+ limit is required because the iovec structure must be
+ invariant (to the user), thus a copy needs to be made
+ by the interface routines. The limit is merely a
+ control over the amount of stack space used by the
+ readv()/writev() functions."
+
+ }
+
# ----------------------------------------------------------------
# Tests
cdl_option CYGPKG_IO_FILEIO_TESTS {
display "Fileio tests"
Index: io/fileio/current/src/io.cxx
===================================================================
RCS file: /misc/cvsfiles/ecos/packages/io/fileio/current/src/io.cxx,v
retrieving revision 1.6
diff -u -5 -p -r1.6 io.cxx
--- io/fileio/current/src/io.cxx 23 May 2002 23:06:09 -0000 1.6
+++ io/fileio/current/src/io.cxx 3 Nov 2002 19:47:52 -0000
@@ -7,10 +7,11 @@
//==========================================================================
//####ECOSGPLCOPYRIGHTBEGIN####
// -------------------------------------------
// This file is part of eCos, the Embedded Configurable Operating System.
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
+// Copyright (C) 2002 Gary Thomas
//
// eCos is free software; you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free
// Software Foundation; either version 2 or (at your option) any later version.
//
@@ -73,25 +74,38 @@
#define LOCK_FILE( fp ) cyg_file_lock( fp, fp->f_syncmode )
#define UNLOCK_FILE( fp ) cyg_file_unlock( fp, fp->f_syncmode )
//==========================================================================
-// Read from or write to a file
-// This is a common routine for doing both read and write
-// operations. The direction argument controls slight the differences
-// between them.
+// Common wrapper for read/write using an iovec descriptor
+// 'direction' should be O_RDONLY for readv, O_WRONLY for writev
-static ssize_t readwrite( int fd, void *buf, size_t len, int direction )
+static ssize_t
+readwritev( int fd, const cyg_iovec *_iov, int iov_len, int direction )
{
FILEIO_ENTRY();
CYG_CANCELLATION_POINT;
- ssize_t cnt;
- int ret;
+ ssize_t cnt, len;
+ int ret, _idx;
cyg_file *fp;
+ cyg_iovec iov[CYGNUM_FILEIO_IOVEC_MAX];
+ if( iov_len > CYGNUM_FILEIO_IOVEC_MAX )
+ FILEIO_RETURN(EINVAL);
+
+ // Copy 'iovec' structure since it's supposed to be "const"
+ // and some lower level routines might want to change it.
+ // Also accumulate the length of the total I/O request
+ len = 0;
+ for (_idx = 0; _idx < iov_len; _idx++) {
+ len += _iov[_idx].iov_len;
+ iov[_idx].iov_base = _iov[_idx].iov_base;
+ iov[_idx].iov_len = _iov[_idx].iov_len;
+ }
+
if( len > SSIZE_MAX )
FILEIO_RETURN(EINVAL);
fp = cyg_fp_get( fd );
@@ -103,27 +117,23 @@ static ssize_t readwrite( int fd, void *
cyg_fp_free( fp );
FILEIO_RETURN(EBADF);
}
cyg_uio uio;
- cyg_iovec iov;
cyg_fileop_readwrite *op;
- iov.iov_base = buf;
- iov.iov_len = len;
- uio.uio_iov = &iov;
- uio.uio_iovcnt = 1;
+ uio.uio_iov = iov;
+ uio.uio_iovcnt = iov_len;
uio.uio_resid = len;
uio.uio_segflg = UIO_USERSPACE;
cnt = len;
if( direction == O_RDONLY )
uio.uio_rw = UIO_READ, op = fp->f_ops->fo_read;
else
uio.uio_rw = UIO_WRITE, op = fp->f_ops->fo_write;
-
LOCK_FILE( fp );
ret = op( fp, &uio );
@@ -144,20 +154,43 @@ static ssize_t readwrite( int fd, void *
//==========================================================================
// Read from file
__externC ssize_t read( int fd, void *buf, size_t len )
{
- return readwrite( fd, buf, len, O_RDONLY );
+ cyg_iovec _iov;
+
+ _iov.iov_base = buf;
+ _iov.iov_len = len;
+ return readwritev(fd, &_iov, 1, O_RDONLY);
}
//==========================================================================
// Write to a file
__externC ssize_t write( int fd, const void *buf, size_t len )
{
- return readwrite( fd, (void *)buf, len, O_WRONLY );
+ cyg_iovec _iov;
+
+ _iov.iov_base = (void *)buf;
+ _iov.iov_len = len;
+ return readwritev(fd, &_iov, 1, O_WRONLY);
+}
+
+//==========================================================================
+// Read via an iovec
+__externC ssize_t readv( int fd, const cyg_iovec *_iov, int iov_len )
+{
+ return readwritev(fd, _iov, iov_len, O_RDONLY);
+}
+
+//==========================================================================
+// Write via an iovec
+__externC ssize_t writev( int fd, const cyg_iovec *_iov, int iov_len )
+{
+ return readwritev(fd, _iov, iov_len, O_WRONLY);
}
+
//==========================================================================
// Close a file
__externC int close( int fd )
Index: net/bsd_tcpip/current/ChangeLog
===================================================================
RCS file: /misc/cvsfiles/ecos-opt/net/net/bsd_tcpip/current/ChangeLog,v
retrieving revision 1.8
diff -u -5 -p -r1.8 ChangeLog
--- net/bsd_tcpip/current/ChangeLog 31 Jul 2002 14:02:18 -0000 1.8
+++ net/bsd_tcpip/current/ChangeLog 3 Nov 2002 18:56:44 -0000
@@ -1,5 +1,12 @@
+2002-11-03 Gary Thomas <gthomas@ecoscentric.com>
+
+ * src/sys/kern/sockio.c (bsd_getname): Fix error where getsockname()
+ was actually performing getpeername().
+
+ * include/sys/uio.h: New file - compatability wrapper.
+
2002-07-31 Gary Thomas <gary@chez-thomas.org>
* src/sys/netinet/in_cksum.c: Fix problem on big endian machines.
2002-07-26 Gary Thomas <gary@chez-thomas.org>
Index: net/bsd_tcpip/current/include/sys/uio.h
===================================================================
RCS file: net/bsd_tcpip/current/include/sys/uio.h
diff -N net/bsd_tcpip/current/include/sys/uio.h
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ net/bsd_tcpip/current/include/sys/uio.h 3 Nov 2002 18:53:25 -0000
@@ -0,0 +1,67 @@
+//==========================================================================
+//
+// net/sys/uio.h
+//
+// Compatability wrapper for <sys/uio.h>
+//
+//==========================================================================
+//####ECOSGPLCOPYRIGHTBEGIN####
+// -------------------------------------------
+// This file is part of eCos, the Embedded Configurable Operating System.
+// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
+// Copyright (C) 2002 Gary Thomas
+//
+// eCos is free software; you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation; either version 2 or (at your option) any later version.
+//
+// eCos is distributed in the hope that it will be useful, but WITHOUT ANY
+// WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+// for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with eCos; if not, write to the Free Software Foundation, Inc.,
+// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+//
+// As a special exception, if other files instantiate templates or use macros
+// or inline functions from this file, or you compile this file and link it
+// with other works to produce a work based on this file, this file does not
+// by itself cause the resulting work to be covered by the GNU General Public
+// License. However the source code for this file must still be made available
+// in accordance with section (3) of the GNU General Public License.
+//
+// This exception does not invalidate any other reasons why a work based on
+// this file might be covered by the GNU General Public License.
+//
+// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
+// at http://sources.redhat.com/ecos/ecos-license/
+// -------------------------------------------
+//####ECOSGPLCOPYRIGHTEND####
+//==========================================================================
+//#####DESCRIPTIONBEGIN####
+//
+// Author(s): gthomas
+// Contributors: gthomas
+// Date: 2002-11-03
+// Purpose:
+// Description:
+//
+//
+//####DESCRIPTIONEND####
+//
+//==========================================================================
+
+#ifndef _CYGONCE_SYS_UIO_H_
+#define _CYGONCE_SYS_UIO_H_
+
+#include <pkgconf/io_fileio.h> // IOVEC_MAX
+#include <cyg/io/file.h> // Definition of 'struct iovec'
+
+#define UIO_MAXIOV CYGNUM_FILEIO_IOVEC_MAX
+
+// Function prototypes
+__externC ssize_t readv(int fd, const struct iovec *iov, int iov_len);
+__externC ssize_t writev(int fd, const struct iovec *iov, int iov_len);
+
+#endif // _CYGONCE_SYS_UIO_H_
Index: net/bsd_tcpip/current/src/sys/kern/sockio.c
===================================================================
RCS file: /misc/cvsfiles/ecos-opt/net/net/bsd_tcpip/current/src/sys/kern/sockio.c,v
retrieving revision 1.1
diff -u -5 -p -r1.1 sockio.c
--- net/bsd_tcpip/current/src/sys/kern/sockio.c 20 May 2002 22:25:02 -0000 1.1
+++ net/bsd_tcpip/current/src/sys/kern/sockio.c 2 Nov 2002 14:06:51 -0000
@@ -465,19 +465,18 @@ static int
bsd_getname(cyg_file *fp, sockaddr *asa, socklen_t *alen, int peer)
{
struct socket *so;
socklen_t len = 0;
int error;
- int type = peer ? PRU_PEERADDR : PRU_SOCKADDR;
sockaddr *sa;
if( alen != NULL)
len = *alen;
so = (struct socket *)fp->f_data;
sa = 0;
- if (type) {
+ if (peer) {
// getpeername()
if ((so->so_state & (SS_ISCONNECTED|SS_ISCONFIRMING)) == 0) {
return (ENOTCONN);
}
error = (*so->so_proto->pr_usrreqs->pru_peeraddr)(so, &sa);
--
------------------------------------------------------------
Gary Thomas |
eCosCentric, Ltd. |
+1 (970) 229-1963 | eCos & RedBoot experts
gthomas@ecoscentric.com |
http://www.ecoscentric.com/ |
------------------------------------------------------------