Bug 16643 - Wishlist: Don't convert in 'writeChar' to fifo connection on Windows
Summary: Wishlist: Don't convert in 'writeChar' to fifo connection on Windows
Status: UNCONFIRMED
Alias: None
Product: R
Classification: Unclassified
Component: Wishlist (show other bugs)
Version: R 3.2.2
Hardware: ix86 (32-bit) Windows 32-bit
: P5 enhancement
Assignee: R-core
URL:
Depends on:
Blocks:
 
Reported: 2015-12-24 17:39 UTC by Suharto Anggono
Modified: 2016-05-08 15:25 UTC (History)
1 user (show)

See Also:


Attachments
Attempted fix (3.09 KB, patch)
2015-12-24 17:54 UTC, Suharto Anggono
Details | Diff
Source code of example reader (1.11 KB, text/x-csrc)
2016-05-08 15:25 UTC, Suharto Anggono
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Suharto Anggono 2015-12-24 17:39:42 UTC
On Windows, I tried to transfer data from R to an application via named pipe.

con <- fifo("\\\\.\\pipe\\datapipe", "wb")
writeChar("A       B       ", con, eos = NULL)
close(con)

When I ran something like above, the display in the receiving application showed longer data with gap between each sent character. It was not the expected data to be seen by the application. Where did the gap come from?

> Sys.getlocale()
[1] "LC_COLLATE=English_United States.1252;LC_CTYPE=English_United States.1252;L
C_MONETARY=English_United States.1252;LC_NUMERIC=C;LC_TIME=English_United States
.1252"

In https://svn.r-project.org/R/trunk/src/main/connections.c, in function 'fifo_write' for Windows, there is "Convert char* to wchar_t*" part. Apparently, that's the culprit. It seems that the gap between each character was null byte.

I wish no conversion were done, like 'writeChar' to file.
Comment 1 Suharto Anggono 2015-12-24 17:54:02 UTC
Created attachment 1952 [details]
Attempted fix

The patch in Comment 2 of Bug 15600 is included.

Conversions in functions 'fifo_read' and 'fifo_fgetc_internal' for Windows are also removed, following 'fifo_write'. I think that conversions in the functions are not necessary, like in the corresponding functions for other connections. For text mode, 'iconv' has been applied outside the functions.
Comment 2 Bernd Feige 2016-04-05 09:05:28 UTC
I'd also vote for removal of the wchar conversion. I'm trying to get a fifo-based connection to work similarly on Linux and Windows and that means to get a stream of bytes across the connection unmodified, at least if "wb" is used.

Thanks!
Comment 3 Suharto Anggono 2016-05-08 15:25:13 UTC
Created attachment 2087 [details]
Source code of example reader

How to use:
1. Compile the source to an executable (*.exe).
2. In R, run the code in Description:
con <- fifo("\\\\.\\pipe\\datapipe", "wb")
writeChar("A       B       ", con, eos = NULL)
close(con)
3. In a Command Prompt (cmd.exe) window, run the executable from step 1.

Output from the executable:
pread: waiting for the pipe...
pread: the pipe is ready
Opened the pipe
41
00
20
00
20
00
20
00
20
00
20
00
20
00
20
00
42
00
20
00
20
00
20
00
20
00
20
00
20
00
20
00
ReadFile failed -- probably EOF