Bumped copyright dates for 2013
[barry.git] / test / ptyio.cc
blob0a7caca33e002440b3e9ca3173d810bc9570dd39
1 ///
2 /// \file ptyio.cc
3 /// Simple test program for pppob's -t pty option.
4 ///
6 /*
7 Copyright (C) 2012-2013, Net Direct Inc. (http://www.netdirect.ca/)
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18 See the GNU General Public License in the COPYING file at the
19 root directory of this project for more details.
22 #include <iostream>
23 #include <sys/types.h>
24 #include <sys/stat.h>
25 #include <fcntl.h>
26 #include <pthread.h>
27 #include <termios.h>
28 #include <unistd.h>
29 #include <stdio.h>
31 using namespace std;
33 struct ioconfig
35 int read;
36 int write;
39 void* readwrite(void *arg)
41 struct ioconfig *io = (struct ioconfig *) arg;
42 for (;;) {
43 char buffer[4096];
44 ssize_t count = read(io->read, buffer, sizeof(buffer));
45 write(1, "Got data: ", 10);
46 write(1, buffer, count);
47 write(io->write, buffer, count);
49 return 0;
52 int main(int argc, char *argv[])
54 if( argc < 2 )
55 return 1;
57 int slave = open(argv[1], O_RDWR);
58 if( slave == -1 )
59 return 2;
61 // set raw mode
62 struct termios tp;
63 tcgetattr(slave, &tp);
64 cfmakeraw(&tp);
65 tcsetattr(slave, TCSANOW, &tp);
67 struct ioconfig io1, io2;
68 io1.read = 0;
69 io1.write = slave;
70 io2.read = slave;
71 io2.write = 1;
73 pthread_t iot1, iot2;
74 pthread_create(&iot1, NULL, &readwrite, &io1);
75 pthread_create(&iot2, NULL, &readwrite, &io2);
77 pthread_join(iot1, NULL);
78 pthread_join(iot2, NULL);
80 return 0;