From: <pau...@us...> - 2009-08-27 17:24:05
|
Revision: 6164 http://octave.svn.sourceforge.net/octave/?rev=6164&view=rev Author: paulsundvall Date: 2009-08-27 17:23:57 +0000 (Thu, 27 Aug 2009) Log Message: ----------- Added version numbers to get the code working in octave 3.0. This is to reflect the change in naming convention(?) from using G instead of FS. See the commit at revision 6070. Revision Links: -------------- http://octave.svn.sourceforge.net/octave/?rev=6070&view=rev Modified Paths: -------------- trunk/octave-forge/main/sockets/src/Makefile trunk/octave-forge/main/sockets/src/sockets.cc Modified: trunk/octave-forge/main/sockets/src/Makefile =================================================================== --- trunk/octave-forge/main/sockets/src/Makefile 2009-08-27 17:11:26 UTC (rev 6163) +++ trunk/octave-forge/main/sockets/src/Makefile 2009-08-27 17:23:57 UTC (rev 6164) @@ -1,10 +1,20 @@ OCT = sockets.oct SRC := $(OCT:.oct=.cc) +#See which octave version we run by querying mkoctfile for its version +#string. (Is there a better way to do this? This looks horrible.) +majorversion :=$(shell mkoctfile --version 2>&1 |sed -e 's/^.* \([0-9]*\)\.\([0-9]*\).\([0-9]*\)$$/\1/g') +minorversion:=$(shell mkoctfile --version 2>&1 |sed -e 's/^.* \([0-9]*\)\.\([0-9]*\).\([0-9]*\)$$/\2/g') +microversion:=$(shell mkoctfile --version 2>&1 |sed -e 's/^.* \([0-9]*\)\.\([0-9]*\).\([0-9]*\)$$/\3/g') + +VFLAGS=-DMAJORVERSION=$(majorversion) +VFLAGS+=-DMINORVERSION=$(minorversion) +VFLAGS+=-DMICROVERSION=$(microversion) + all: $(OCT) %.oct: %.cc - mkoctfile -s $< + mkoctfile $(VFLAGS) -s $< test: $(OCT) test_octave_sockets Modified: trunk/octave-forge/main/sockets/src/sockets.cc =================================================================== --- trunk/octave-forge/main/sockets/src/sockets.cc 2009-08-27 17:11:26 UTC (rev 6163) +++ trunk/octave-forge/main/sockets/src/sockets.cc 2009-08-27 17:23:57 UTC (rev 6164) @@ -199,12 +199,26 @@ DEFINE_OCTAVE_ALLOCATOR (octave_socket); DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_socket, "octave_socket", "octave_socket"); + + // This macro must start with DEFUN_DLD so that the automatic collection -// of function helps can take place. -#define DEFUN_DLD_SOCKET_CONSTANT(name, help ) \ -DEFUNX_DLD ( #name, F ## name, G ## name, args, nargout, help) \ -{ return octave_value( name ); }; +// of function helps can take place. To get the code working in +// multiple versions of octave, we have to check the version number. +#if !defined(MINORVERSION) || !defined(MAJORVERSION) +# error "please define MAJORVERSION and MINORVERSION to the octave version numbers" +#endif +#if MAJORVERSION==3 && MINORVERSION<2 +# define DEFUN_DLD_SOCKET_CONSTANT(name, help ) \ + DEFUNX_DLD ( #name, F ## name, FS ## name, args, nargout, help) \ + { return octave_value( name ); }; +#else +# define DEFUN_DLD_SOCKET_CONSTANT(name, help ) \ + DEFUNX_DLD ( #name, F ## name, G ## name, args, nargout, help) \ + { return octave_value( name ); }; +#endif + + // PKG_ADD: autoload ("AF_UNIX", "sockets.oct"); DEFUN_DLD_SOCKET_CONSTANT(AF_UNIX, "socket constant" ); #ifndef __WIN32__ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <gof...@us...> - 2011-09-01 21:49:56
|
Revision: 8485 http://octave.svn.sourceforge.net/octave/?rev=8485&view=rev Author: goffioul Date: 2011-09-01 21:49:49 +0000 (Thu, 01 Sep 2011) Log Message: ----------- Allow compilation with octave development sources and Win32 API. Modified Paths: -------------- trunk/octave-forge/main/sockets/src/Makefile trunk/octave-forge/main/sockets/src/sockets.cc Modified: trunk/octave-forge/main/sockets/src/Makefile =================================================================== --- trunk/octave-forge/main/sockets/src/Makefile 2011-09-01 15:12:29 UTC (rev 8484) +++ trunk/octave-forge/main/sockets/src/Makefile 2011-09-01 21:49:49 UTC (rev 8485) @@ -3,9 +3,9 @@ #See which octave version we run by querying mkoctfile for its version #string. (Is there a better way to do this? This looks horrible.) -majorversion :=$(shell mkoctfile --version 2>&1 |sed -e 's/^.* \([0-9]*\)\.\([0-9]*\).\([0-9]*\)$$/\1/g') -minorversion:=$(shell mkoctfile --version 2>&1 |sed -e 's/^.* \([0-9]*\)\.\([0-9]*\).\([0-9]*\)$$/\2/g') -microversion:=$(shell mkoctfile --version 2>&1 |sed -e 's/^.* \([0-9]*\)\.\([0-9]*\).\([0-9]*\)$$/\3/g') +majorversion :=$(shell mkoctfile --version 2>&1 |sed -e 's/^.* \([0-9]*\)\.\([0-9]*\).\([0-9]*\)+\?$$/\1/g') +minorversion:=$(shell mkoctfile --version 2>&1 |sed -e 's/^.* \([0-9]*\)\.\([0-9]*\).\([0-9]*\)+\?$$/\2/g') +microversion:=$(shell mkoctfile --version 2>&1 |sed -e 's/^.* \([0-9]*\)\.\([0-9]*\).\([0-9]*\)+\?$$/\3/g') VFLAGS=-DMAJORVERSION=$(majorversion) VFLAGS+=-DMINORVERSION=$(minorversion) Modified: trunk/octave-forge/main/sockets/src/sockets.cc =================================================================== --- trunk/octave-forge/main/sockets/src/sockets.cc 2011-09-01 15:12:29 UTC (rev 8484) +++ trunk/octave-forge/main/sockets/src/sockets.cc 2011-09-01 21:49:49 UTC (rev 8485) @@ -39,6 +39,7 @@ #endif #else typedef unsigned int socklen_t; +#include <winsock2.h> #endif #include <errno.h> @@ -254,8 +255,10 @@ // PKG_ADD: autoload ("MSG_PEEK", "sockets.oct"); DEFUN_DLD_SOCKET_CONSTANT(MSG_PEEK, "socket constant" ); +#ifndef __WIN32__ // PKG_ADD: autoload ("MSG_DONTWAIT", "sockets.oct"); DEFUN_DLD_SOCKET_CONSTANT(MSG_DONTWAIT, "socket constant" ); +#endif // PKG_ADD: autoload ("MSG_WAITALL", "sockets.oct"); DEFUN_DLD_SOCKET_CONSTANT(MSG_WAITALL, "socket constant" ); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pau...@us...> - 2012-07-23 20:05:40
|
Revision: 10764 http://octave.svn.sourceforge.net/octave/?rev=10764&view=rev Author: pauldreik Date: 2012-07-23 20:05:33 +0000 (Mon, 23 Jul 2012) Log Message: ----------- refreshed the recv() function: * removed type conversion by constructing the output directly * assign output arguments also when the underlying recv() returns <=0, so empty data is returned. * updated the documentation string with clarification. * bug out with error if the user has to many output arguments Thanks to Sebastian Singer for reporting the error. Modified Paths: -------------- trunk/octave-forge/main/sockets/src/Makefile trunk/octave-forge/main/sockets/src/sockets.cc Modified: trunk/octave-forge/main/sockets/src/Makefile =================================================================== --- trunk/octave-forge/main/sockets/src/Makefile 2012-07-23 16:36:06 UTC (rev 10763) +++ trunk/octave-forge/main/sockets/src/Makefile 2012-07-23 20:05:33 UTC (rev 10764) @@ -5,6 +5,10 @@ MKOCTFILE ?= mkoctfile OCTAVE ?= octave +#windows users should link with -lws2_32 (on mingw, at least). If you +#know how to detect windows and find the appropriate linker flag here, +#please drop a mail to the octave-dev mailing list. + #See which octave version we run by querying mkoctfile for its version #string. This is needed because there was an octave macro that changed #from 3.0 to 3.2. When 3.0 is considered long gone, this is not Modified: trunk/octave-forge/main/sockets/src/sockets.cc =================================================================== --- trunk/octave-forge/main/sockets/src/sockets.cc 2012-07-23 16:36:06 UTC (rev 10763) +++ trunk/octave-forge/main/sockets/src/sockets.cc 2012-07-23 20:05:33 UTC (rev 10764) @@ -651,13 +651,19 @@ "of recv.\n" "\n" "The read data is returned in an uint8 array data. The number of\n" - "bytes read is returned in count\n" + "bytes read is returned in count.\n" "\n" "You can get non-blocking operation by using the flag MSG_DONTWAIT\n" "which makes the recv() call return immediately. If there are no\n" - "data, -1 is returned.\n" + "data, -1 is returned in count.\n" "See the recv() man pages for further details.\n") { + if(nargout>2) + { + error("recv: please use at most two output arguments."); + return octave_value(-1); + } + int retval = 0; int flags = 0; @@ -678,7 +684,7 @@ s = &((octave_socket &)rep); } else if ( args(0).is_scalar_type() ) - { + {//what happens if fd does not exist in socket_map? int fd = args(0).int_value(); s = socket_map[fd]; } @@ -701,26 +707,32 @@ retval = ::recv( s->get_sock_fd(), ( char* )buf, len, flags ); #endif + octave_value_list return_list; + uint8NDArray data; - octave_value_list return_list; //always return the status in the second output parameter return_list(1) = retval; if(retval<0) { //We get -1 if an error occurs,or if there is no data and the //socket is non-blocking. We should return in both cases. + return_list(0) = data; } else if (0==retval) { //The peer has shut down. + return_list(0) = data; } else { - //Normal behaviour. - Matrix return_buf(1,retval); - + //Normal behaviour. Copy the buffer to the output variable. For + //backward compatibility, a row vector is returned. + dim_vector d; + d(0)=1; + d(1)=retval; + data.resize(d); + + //this could possibly be made more efficient with memcpy and + //fortran_vec() instead. for ( int i = 0 ; i < retval ; i++ ) - return_buf(0,i) = buf[i]; + data(i) = buf[i]; - octave_value in_buf(return_buf); - octave_value out_buf; - OCTAVE_TYPE_CONV( in_buf, out_buf, uint8 ); - return_list(0) = out_buf; + return_list(0) = data; } delete[] buf; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |