From: <i7...@us...> - 2010-02-18 10:28:47
|
Revision: 6923 http://octave.svn.sourceforge.net/octave/?rev=6923&view=rev Author: i7tiol Date: 2010-02-18 10:28:39 +0000 (Thu, 18 Feb 2010) Log Message: ----------- get rid of read/write compiler warnings Modified Paths: -------------- trunk/octave-forge/main/parallel/src/connect.cc trunk/octave-forge/main/parallel/src/sclose.cc Modified: trunk/octave-forge/main/parallel/src/connect.cc =================================================================== --- trunk/octave-forge/main/parallel/src/connect.cc 2010-02-18 06:22:10 UTC (rev 6922) +++ trunk/octave-forge/main/parallel/src/connect.cc 2010-02-18 10:28:39 UTC (rev 6923) @@ -43,6 +43,18 @@ // COMM +static void read_if_no_error (int fd, void *buf, size_t count, int est) { + if (! est) + if (read (fd, buf, count) < (ssize_t)count) + error ("read error"); +} + +static void write_if_no_error (int fd, const void *buf, size_t count, int est) { + if (! est) + if (write (fd, buf, count) < (ssize_t)count) + error ("write error"); +} + DEFUN_DLD (connect, args, , "connect (hosts)\n\ \n\ @@ -114,12 +126,11 @@ pid=getpid(); nl=htonl(num_nodes); - write(sock,&nl,sizeof(int)); + write_if_no_error(sock,&nl,sizeof(int),error_state); nl=htonl(i); - write(sock,&nl,sizeof(int)); + write_if_no_error(sock,&nl,sizeof(int),error_state); nl=htonl(pid); - write(sock,&nl,sizeof(int)); - + write_if_no_error(sock,&nl,sizeof(int),error_state); host=(char *)calloc(128,sizeof(char)); for(j=0;j<row;j++){ strncpy(host,&cm.data()[col*j],col); @@ -130,16 +141,16 @@ *pt='\0'; len=strlen(host)+1; nl=htonl(len); - write(sock,&nl,sizeof(int)); - write(sock,host,len); + write_if_no_error(sock,&nl,sizeof(int),error_state); + write_if_no_error(sock,host,len,error_state); } free(host); int comm_len; std::string directory = octave_env::getcwd (); comm_len=directory.length(); nl=htonl(comm_len); - write(sock,&nl,sizeof(int)); - write(sock,directory.c_str(),comm_len); + write_if_no_error(sock,&nl,sizeof(int),error_state); + write_if_no_error(sock,directory.c_str(),comm_len,error_state); } usleep(100); @@ -196,7 +207,7 @@ int len=0,result=0;; //send pppid nl=htonl(pid); - write(sock,&nl,sizeof(int)); + write_if_no_error(sock,&nl,sizeof(int),error_state); //send name size strncpy(myname,cm.data(),col); pt=strchr(myname,' '); @@ -206,16 +217,16 @@ *pt='\0'; len=strlen(myname); nl=htonl(len); - write(sock,&nl,sizeof(int)); + write_if_no_error(sock,&nl,sizeof(int),error_state); //send name - write(sock,myname,len+1); + write_if_no_error(sock,myname,len+1,error_state); //recv result code - read(sock,&nl,sizeof(int)); + read_if_no_error(sock,&nl,sizeof(int),error_state); result=ntohl(nl); if(result==0){ sock_v[i]=sock; //recv endian - read(sock,&nl,sizeof(int)); + read_if_no_error(sock,&nl,sizeof(int),error_state); sock_v[i+2*row]=ntohl(nl); //send endian #if defined (__BYTE_ORDER) @@ -225,7 +236,7 @@ #else # error "can not determine the byte order" #endif - write(sock,&nl,sizeof(int)); + write_if_no_error(sock,&nl,sizeof(int),error_state); break; }else{ close(sock); @@ -238,7 +249,7 @@ char lf='\n'; for(i=1;i<row;i++){ - write((int)sock_v[i+row],&lf,sizeof(char)); + write_if_no_error((int)sock_v[i+row],&lf,sizeof(char),error_state); // cout << i+row <<endl; } } Modified: trunk/octave-forge/main/parallel/src/sclose.cc =================================================================== --- trunk/octave-forge/main/parallel/src/sclose.cc 2010-02-18 06:22:10 UTC (rev 6922) +++ trunk/octave-forge/main/parallel/src/sclose.cc 2010-02-18 10:28:39 UTC (rev 6923) @@ -53,7 +53,7 @@ if(args.length () == 1) { - int i,nsock=0,sock,k,error_code,err=0,nl; + int i,nsock=0,sock,k,err=0,nl; nsock=args(0).matrix_value().rows()*2; @@ -80,9 +80,12 @@ if(pollfd[k].revents&POLLIN){ pid=getpid(); - read(pollfd[k].fd,&nl,sizeof(int)); - error_code=ntohl(nl); - write(pollfd[k].fd,&nl,sizeof(int)); + + if (read(pollfd[k].fd,&nl,sizeof(int)) < (ssize_t)sizeof(int)) + error ("read error"); + if (! error_state) + if (write(pollfd[k].fd,&nl,sizeof(int)) < (ssize_t)sizeof(int)) + error ("write error"); error("error occurred in %s\n\tsee %s:/tmp/octave_error-%s_%5d.log for detail",hehe->h_name,hehe->h_name,hehe->h_name,pid ); } if(pollfd[k].revents&POLLERR){ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <i7...@us...> - 2010-08-11 13:28:15
|
Revision: 7507 http://octave.svn.sourceforge.net/octave/?rev=7507&view=rev Author: i7tiol Date: 2010-08-11 13:28:08 +0000 (Wed, 11 Aug 2010) Log Message: ----------- Added select_sockets.cc. - select_sockets.cc: new file, calles select on data connections of "connect". - pserver.cc: fixed buffer size in outgoing connections. Modified Paths: -------------- trunk/octave-forge/main/parallel/src/Makefile trunk/octave-forge/main/parallel/src/pserver.cc Added Paths: ----------- trunk/octave-forge/main/parallel/src/select_sockets.cc Modified: trunk/octave-forge/main/parallel/src/Makefile =================================================================== --- trunk/octave-forge/main/parallel/src/Makefile 2010-08-10 21:24:28 UTC (rev 7506) +++ trunk/octave-forge/main/parallel/src/Makefile 2010-08-11 13:28:08 UTC (rev 7507) @@ -1,5 +1,5 @@ OCTS = sclose.oct connect.oct pserver.oct \ - recv.oct reval.oct send.oct \ + recv.oct reval.oct send.oct select_sockets.oct \ __bw_is_locked__.oct __bw_lock_file__.oct \ __bw_unlock_file__.oct \ __bw_prcv__.oct __bw_psend__.oct __internal_exit__.oct \ Modified: trunk/octave-forge/main/parallel/src/pserver.cc =================================================================== --- trunk/octave-forge/main/parallel/src/pserver.cc 2010-08-10 21:24:28 UTC (rev 7506) +++ trunk/octave-forge/main/parallel/src/pserver.cc 2010-08-11 13:28:08 UTC (rev 7507) @@ -504,7 +504,7 @@ usleep(5000); } } - int bufsize=262144; + int bufsize=BUFF_SIZE; socklen_t ol; ol=sizeof(bufsize); setsockopt(dsock,SOL_SOCKET,SO_SNDBUF,&bufsize,ol); Added: trunk/octave-forge/main/parallel/src/select_sockets.cc =================================================================== --- trunk/octave-forge/main/parallel/src/select_sockets.cc (rev 0) +++ trunk/octave-forge/main/parallel/src/select_sockets.cc 2010-08-11 13:28:08 UTC (rev 7507) @@ -0,0 +1,140 @@ +// Copyright (C) 2010 Olaf Till <ola...@un...> + +// This program 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 3 of the License, or +// (at your option) any later version. + +// This program 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 this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +#include <octave/oct.h> +#include <octave/oct-stream.h> + +#ifdef POSIX +#include <sys/select.h> +#else +#include <sys/time.h> +#include <sys/types.h> +#include <unistd.h> +#endif +#include <errno.h> +#include <map> + +DEFUN_DLD (select_sockets, args, nargout, + "-*- texinfo -*-\n\ +@deftypefn {Loadable Function} {[@var{n}, @var{idx}] =} select_sockets (@var{sockets}, @var{timeout}[, @var{nfds}])\n\ +Calls Unix @code{select}.\n\ +@var{sockets}: valid sockets matrix as returned by @code{connect}.\n\ +@var{timeout}: seconds, negative for infinite.\n\ +@var{nfds}: optional, default is Unix' FD_SETSIZE (platform specific).\n\ +Passed to Unix @code{select} as the first argument --- see there.\n\ +An error is returned if nfds or a watched filedescriptor \n\ +plus one exceeds FD_SETSIZE.\n\ +Return values are:\n\ +@var{idx}: index vector to rows in @var{sockets} with pending input\n\ +readable with @code{recv}.\n\ +@var{n}: number of rows in @var{sockets} with pending input.\n\ +@end deftypefn") +{ + octave_value_list retval; + int nargin = args.length (); + int i, fid, nfds, n, nr, act; + double argtout, *fvec; + timeval tout; + timeval *timeout = &tout; + ColumnVector read_fds; + + if (nargin == 2) + nfds = FD_SETSIZE; + else if (nargin == 3) { + if (! args(2).is_real_scalar ()) { + error ("'nfds' must be a real scalar.\n"); + return retval; + } + nfds = args(2).int_value (); + if (nfds <= 0) { + error ("'nfds' should be greater than zero.\n"); + return retval; + } + if (nfds > FD_SETSIZE) { + error ("'nfds' exceeds systems maximum given by FD_SETSIZE.\n"); + return retval; + } + } + else { + error ("two or three arguments required.\n"); + return retval; + } + if (! args(1).is_real_scalar ()) { + error ("'timeout' must be a real scalar.\n"); + return retval; + } + if ((argtout = args(1).double_value ()) < 0) + timeout = NULL; + else { + double ipart, fpart; + fpart = modf (argtout, &ipart); + tout.tv_sec = lrint (ipart); + tout.tv_usec = lrint (fpart * 1000); + } + if ((nr = args(0).matrix_value().rows()) < 2 || + args(0).matrix_value().columns() != 3) { + error ("First argument must be a valid sockets matrix as returned by 'connect'\n"); + return retval; + } + read_fds = ColumnVector (args(0).matrix_value().column(0)); + + fd_set rfds; + FD_ZERO (&rfds); + for (i = 1; i < read_fds.length (); i++) { + fid = lrint (read_fds(i)); + if (fid >= FD_SETSIZE) { + error ("filedescriptor >= FD_SETSIZE"); + return retval; + } + FD_SET (fid, &rfds); + } + + if ((n = select (nfds, &rfds, NULL, NULL, timeout)) == -1) { + std::string err; + switch (errno) { + case EBADF: + err = "EBADF"; + break; + case EINTR: + err = "EINTR"; + break; + case EINVAL: + err = "EINVAL"; + break; + default: + err = "unknown error"; + } + error ("unix select returned error: %s\n", + err.c_str ()); + return retval; + } + if (nargout > 1) { + for (i = 1, act = 0; i < read_fds.length (); i++) + if (FD_ISSET (lrint (read_fds(i)), &rfds)) act++; + RowVector ridx = RowVector (act); + for (i = 1, fvec = ridx.fortran_vec (); + i < read_fds.length (); i++) + if (FD_ISSET (lrint (read_fds(i)), &rfds)) { + *fvec = double (i + 1); + fvec++; + } + retval(1) = ridx; + } + + retval(0) = n; + + return retval; +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <i7...@us...> - 2011-01-24 17:52:27
|
Revision: 8070 http://octave.svn.sourceforge.net/octave/?rev=8070&view=rev Author: i7tiol Date: 2011-01-24 17:52:20 +0000 (Mon, 24 Jan 2011) Log Message: ----------- Include netinet/in.h for FreeBSD-8 due to user report. Modified Paths: -------------- trunk/octave-forge/main/parallel/src/connect.cc trunk/octave-forge/main/parallel/src/pserver.cc Modified: trunk/octave-forge/main/parallel/src/connect.cc =================================================================== --- trunk/octave-forge/main/parallel/src/connect.cc 2011-01-24 17:45:50 UTC (rev 8069) +++ trunk/octave-forge/main/parallel/src/connect.cc 2011-01-24 17:52:20 UTC (rev 8070) @@ -25,6 +25,7 @@ #include <sys/socket.h> #include <errno.h> #include <netdb.h> +#include <netinet/in.h> // reported necessary for FreeBSD-8 #include "sock-stream.h" Modified: trunk/octave-forge/main/parallel/src/pserver.cc =================================================================== --- trunk/octave-forge/main/parallel/src/pserver.cc 2011-01-24 17:45:50 UTC (rev 8069) +++ trunk/octave-forge/main/parallel/src/pserver.cc 2011-01-24 17:52:20 UTC (rev 8070) @@ -32,6 +32,7 @@ #include <sys/poll.h> #include <errno.h> #include <netdb.h> +#include <netinet/in.h> // reported necessary for FreeBSD-8 #include "sock-stream.h" This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <i7...@us...> - 2011-02-25 08:58:55
|
Revision: 8138 http://octave.svn.sourceforge.net/octave/?rev=8138&view=rev Author: i7tiol Date: 2011-02-25 08:58:49 +0000 (Fri, 25 Feb 2011) Log Message: ----------- Update copyright notices. Modified Paths: -------------- trunk/octave-forge/main/parallel/src/connect.cc trunk/octave-forge/main/parallel/src/pserver.cc trunk/octave-forge/main/parallel/src/recv.cc trunk/octave-forge/main/parallel/src/reval.cc trunk/octave-forge/main/parallel/src/sclose.cc trunk/octave-forge/main/parallel/src/send.cc trunk/octave-forge/main/parallel/src/sock-stream.cc trunk/octave-forge/main/parallel/src/sock-stream.h Modified: trunk/octave-forge/main/parallel/src/connect.cc =================================================================== --- trunk/octave-forge/main/parallel/src/connect.cc 2011-02-25 08:44:30 UTC (rev 8137) +++ trunk/octave-forge/main/parallel/src/connect.cc 2011-02-25 08:58:49 UTC (rev 8138) @@ -1,6 +1,7 @@ /* Copyright (C) 2002 Hayato Fujiwara +Copyright (C) 2010, 2011 Olaf Till <ola...@un...> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by Modified: trunk/octave-forge/main/parallel/src/pserver.cc =================================================================== --- trunk/octave-forge/main/parallel/src/pserver.cc 2011-02-25 08:44:30 UTC (rev 8137) +++ trunk/octave-forge/main/parallel/src/pserver.cc 2011-02-25 08:58:49 UTC (rev 8138) @@ -1,6 +1,7 @@ /* Copyright (C) 2002 Hayato Fujiwara +Copyright (C) 2010, 2011 Olaf Till <ola...@un...> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by Modified: trunk/octave-forge/main/parallel/src/recv.cc =================================================================== --- trunk/octave-forge/main/parallel/src/recv.cc 2011-02-25 08:44:30 UTC (rev 8137) +++ trunk/octave-forge/main/parallel/src/recv.cc 2011-02-25 08:58:49 UTC (rev 8138) @@ -1,6 +1,6 @@ // Copyright (C) 2002 Hayato Fujiwara -// Copyright (C) 2010 Olaf Till <ola...@un...> +// Copyright (C) 2010, 2011 Olaf Till <ola...@un...> // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by Modified: trunk/octave-forge/main/parallel/src/reval.cc =================================================================== --- trunk/octave-forge/main/parallel/src/reval.cc 2011-02-25 08:44:30 UTC (rev 8137) +++ trunk/octave-forge/main/parallel/src/reval.cc 2011-02-25 08:58:49 UTC (rev 8138) @@ -1,6 +1,7 @@ /* Copyright (C) 2002 Hayato Fujiwara +Copyright (C) 2010, 2011 Olaf Till <ola...@un...> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by Modified: trunk/octave-forge/main/parallel/src/sclose.cc =================================================================== --- trunk/octave-forge/main/parallel/src/sclose.cc 2011-02-25 08:44:30 UTC (rev 8137) +++ trunk/octave-forge/main/parallel/src/sclose.cc 2011-02-25 08:58:49 UTC (rev 8138) @@ -1,6 +1,7 @@ /* Copyright (C) 2002 Hayato Fujiwara +Copyright (C) 2010, 2011 Olaf Till <ola...@un...> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by Modified: trunk/octave-forge/main/parallel/src/send.cc =================================================================== --- trunk/octave-forge/main/parallel/src/send.cc 2011-02-25 08:44:30 UTC (rev 8137) +++ trunk/octave-forge/main/parallel/src/send.cc 2011-02-25 08:58:49 UTC (rev 8138) @@ -1,6 +1,6 @@ // Copyright (C) 2002 Hayato Fujiwara -// Copyright (C) 2010 Olaf Till <ola...@un...> +// Copyright (C) 2010, 2011 Olaf Till <ola...@un...> // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by Modified: trunk/octave-forge/main/parallel/src/sock-stream.cc =================================================================== --- trunk/octave-forge/main/parallel/src/sock-stream.cc 2011-02-25 08:44:30 UTC (rev 8137) +++ trunk/octave-forge/main/parallel/src/sock-stream.cc 2011-02-25 08:58:49 UTC (rev 8138) @@ -1,4 +1,4 @@ -// Copyright (C) 2010 Olaf Till +// Copyright (C) 2010, 2011 Olaf Till // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by Modified: trunk/octave-forge/main/parallel/src/sock-stream.h =================================================================== --- trunk/octave-forge/main/parallel/src/sock-stream.h 2011-02-25 08:44:30 UTC (rev 8137) +++ trunk/octave-forge/main/parallel/src/sock-stream.h 2011-02-25 08:58:49 UTC (rev 8138) @@ -1,4 +1,4 @@ -// Copyright (C) 2010 Olaf Till +// Copyright (C) 2010, 2011 Olaf Till // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ean...@us...> - 2012-08-07 18:54:47
|
Revision: 10839 http://octave.svn.sourceforge.net/octave/?rev=10839&view=rev Author: eandrius Date: 2012-08-07 18:54:41 +0000 (Tue, 07 Aug 2012) Log Message: ----------- Fix for missing headers in parallel package Modified Paths: -------------- trunk/octave-forge/main/parallel/src/connect.cc trunk/octave-forge/main/parallel/src/pserver.cc trunk/octave-forge/main/parallel/src/recv.cc trunk/octave-forge/main/parallel/src/send.cc Modified: trunk/octave-forge/main/parallel/src/connect.cc =================================================================== --- trunk/octave-forge/main/parallel/src/connect.cc 2012-08-07 11:40:25 UTC (rev 10838) +++ trunk/octave-forge/main/parallel/src/connect.cc 2012-08-07 18:54:41 UTC (rev 10839) @@ -30,6 +30,10 @@ #include <netdb.h> #include <netinet/in.h> // reported necessary for FreeBSD-8 +#if HAVE_UNISTD_H +#include <unistd.h> +#endif + #include "sock-stream.h" static Modified: trunk/octave-forge/main/parallel/src/pserver.cc =================================================================== --- trunk/octave-forge/main/parallel/src/pserver.cc 2012-08-07 11:40:25 UTC (rev 10838) +++ trunk/octave-forge/main/parallel/src/pserver.cc 2012-08-07 18:54:41 UTC (rev 10839) @@ -35,6 +35,10 @@ #include <netdb.h> #include <netinet/in.h> // reported necessary for FreeBSD-8 +#if HAVE_UNISTD_H +#include <unistd.h> +#endif + #include "sock-stream.h" #include "config.h" Modified: trunk/octave-forge/main/parallel/src/recv.cc =================================================================== --- trunk/octave-forge/main/parallel/src/recv.cc 2012-08-07 11:40:25 UTC (rev 10838) +++ trunk/octave-forge/main/parallel/src/recv.cc 2012-08-07 18:54:41 UTC (rev 10839) @@ -27,6 +27,9 @@ #include <netinet/in.h> #include <netdb.h> +#if HAVE_UNISTD_H +#include <unistd.h> +#endif DEFUN_DLD (recv, args, nargout, "recv (socket)\n\ \n\ Modified: trunk/octave-forge/main/parallel/src/send.cc =================================================================== --- trunk/octave-forge/main/parallel/src/send.cc 2012-08-07 11:40:25 UTC (rev 10838) +++ trunk/octave-forge/main/parallel/src/send.cc 2012-08-07 18:54:41 UTC (rev 10839) @@ -26,6 +26,9 @@ #include <netinet/in.h> #include <netdb.h> +#if HAVE_UNISTD_H +#include <unistd.h> +#endif DEFUN_DLD (send, args, , "send (X, sockets)\n\ \n\ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |