New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sysread in utf8 mode returns undefined result, but read input #8184
Comments
From jutta@pobox.comCreated by jutta@pobox.comThis has been seen on perl 5.8.7 and 5.8.6. I'm reading via a nonblocking binary TCP socket in "utf8" mode, I'm reading a certain number of characters. If a server sends The buffer I pass in nevertheless contains the bytes read from Instead of returning undefined, sysread()s result should reflect the Perl Info
|
From @smpeters
Would it be possible for you to send us some sample code that |
The RT System itself - Status changed from 'new' to 'open' |
From jutta@panix.com[Steve Peters via RT]
Sure. Here's a little TCP server, written in C, and a perl This should compile under anything unixy -- save to foo.c, gcc -o ================================= BEGIN ============================= static int int one = 1; s = socket(AF_INET, SOCK_STREAM, 0); memset(&server, 0, sizeof(server)); setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (void *)&one, sizeof(one)); umask(0); if (listen(s, 100) == -1) { int main(int ac, char **av) if (ac < 2 || ac > 3) { port = atoi(av[1]); listener = setup_listen_sock(interface, port); memset(&client, 0, sizeof(client)); while(1) { static char const greeting[] = conn = accept( /* Pretend that with the first part of the protocol completed, And here's the perl "client" that reads in blocks of 12 UTF characters. ================================= BEGIN ============================= use strict; # constants # libraries # open a socket # put the socket in UTF-8 mode. my( $retval, $buffer ); # read from the socket. while (1) { $retval = sysread($socket, $buffer, $BUFSIZE); if ( !defined( print "read: ", $retval, ", buffer: '", $buffer, "'\r\n"; exit 0; The client's socket is set to is non-blocking. So, if, as in If you replace the UTF8 apostrophe from the server data wtih a ./test.pl And if you make the text just one byte shorter or longer (E.g. write ./test.pl and it's only if there's an UTF-8 character present and the _byte_ -- ./utf8read.pl Note that the characters did "make it" into the buffer, it's Hope this reproduces on your system and helps explain what's Cheers, Jutta <jutta@pobox.com> |
|
Migrated from rt.perl.org#37585 (status was 'open')
Searchable as RT37585$
The text was updated successfully, but these errors were encountered: