0

I've two devices one is a pts (/dev/pts/N) another is a socket(/path/to/socket). I want infinitely read the pts and write that to socket, and infinitely read socket and write to pts.

What I am doing right now is to open both and create a read loop in two threads, But is there any simpler way with pipe that takes some works in kernel space ?

harper
  • 13,345
  • 8
  • 56
  • 105
Neel Basu
  • 12,638
  • 12
  • 82
  • 146
  • You may use `select()` and do the job in one thread. Anyway, most of the time your program will be blocked inside a `wait_event` loop inside the kernel. – mcleod_ideafix Apr 05 '15 at 17:48
  • Only in one direction – mcleod_ideafix Apr 05 '15 at 17:49
  • would it be much different in terms of performance or manageability ? – Neel Basu Apr 05 '15 at 18:19
  • There is already tool for that: [socat](http://www.dest-unreach.org/socat/). Just in case you need tool not the implementation. – myaut Apr 05 '15 at 18:32
  • Though I need a programmatic solution. How would I do the same with socat ? `socat /dev/pts/N UNIX:socket` didn't work. – Neel Basu Apr 05 '15 at 19:01
  • What do you mean by saying "didn't work"? Also, note that if `/dev/pts/X` is opened by someone else (like `xterm`) you will compete for reading with that process. – myaut Apr 05 '15 at 19:51
  • Yes it worked, I had to use `raw` But I want a programmatic solution. because in some cases I need to concatenate some pts or select one of them and then send to socket. also I need to have a rest interface. – Neel Basu Apr 06 '15 at 10:28

0 Answers0