Paul Dreik skrev 2012-07-17 13:45: > Singer, Sebastian skrev 2012-07-12 12:49: >> Hi all, >> >> when calling [data, count] = recv() from the sockets package on a >> closed connection octave emits an error: >> >> error: octave_base_value::print (): wrong type argument `<unknown type>' >> >> error: called from: >> error: socket_server.m ... >> >> I think the return array [data, count] is not initialized correctly, >> when no data could be read. I can get rid of this error with the >> following patch: >> >> Index: sockets.cc >> =================================================================== >> --- sockets.cc (revision 10742) >> +++ sockets.cc (working copy) >> @@ -708,8 +708,10 @@ >> >> 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) = retval; // Make sure return_list is defined >> correctly with some value >> } else if (0==retval) { >> //The peer has shut down. >> + return_list(0) = retval; // Make sure return_list is defined >> correctly with some value >> } else { >> //Normal behaviour. >> Matrix return_buf(1,retval); >> >> Please advise, if this is a proper fix of the problem and if this patch >> can be accepted. >> >> I use octave-3.6.1_gcc4.6.2 (mingw) on windows 7. The sockets package >> was taken from the svn repository. >> Two short scripts for server and client are attached. >> >> In order to compile the sockets package I had to add '-lws2_32' to the >> Makefile to avoid linker errors. What is the correct way to specify >> linker flags platform independently for octave packages? >> >> >> Regards, >> Sebastian. >> > Hi, thank you for the patch. I think you spotted a problem, but I have > other thoughts for the solution. recv() returns the data and the count. > It is meant that count should specify the length of the data read, or > signal an error/no data available (-1) or remote end shutdown (0). For > the last two, the sane thing is to let data be an empty variable. Sloppy > users (no shame on them!) which do not call recv() with two output > arguments will then receive an empty data vector, which is fine to > append to other vectors etc. With your patch, the will receive 0 or -1 > which I guess will be type converted into 255. > > I also do not know how to check that one is on a windows platform in the > makefile. can you try to put the uname command in your makefile and see > what it spits out? > Paul Dreik > > > > ------------------------------------------------------------------------------ > Live Security Virtual Conference > Exclusive live event will cover all the ways today's security and > threat landscape has changed and how IT managers can respond. Discussions > will include endpoint security, mobile security and the latest in malware > threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ > _______________________________________________ > Octave-dev mailing list > Octave-dev@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/octave-dev
I cleaned up a bit. Can you please test the following patch? Index: sockets.cc =================================================================== --- sockets.cc (revision 10746) +++ sockets.cc (arbetskopia) @@ -678,7 +678,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]; } @@ -703,24 +703,29 @@ octave_value_list return_list; + uint8NDArray data; + //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); - + dim_vector d; + d(0)=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; ------------------------------------------------------------------------------ Live Security Virtual Conference Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ _______________________________________________ Octave-dev mailing list Octave-dev@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/octave-dev