Adding first part of infrastructure for tty device handling
This commit is contained in:
parent
608a926edc
commit
538e7932c7
3 changed files with 19 additions and 2 deletions
10
moxerver.c
10
moxerver.c
|
@ -46,6 +46,7 @@ int main(int argc, char *argv[]) {
|
|||
|
||||
unsigned int tcp_port = -1;
|
||||
char tty_path[DEV_PATH] = {'\0'};
|
||||
struct tty_t tty_dev;
|
||||
|
||||
fd_set read_fds;
|
||||
int fdmax;
|
||||
|
@ -96,6 +97,9 @@ int main(int argc, char *argv[]) {
|
|||
fprintf(stderr, "[%s] error: tty path was not specified\n\n", NAME);
|
||||
usage();
|
||||
return -1;
|
||||
} else {
|
||||
/* set tty device path to in tty_dev struct */
|
||||
strcpy(tty_dev.path, tty_path);
|
||||
}
|
||||
|
||||
/* introduction message */
|
||||
|
@ -110,6 +114,12 @@ int main(int argc, char *argv[]) {
|
|||
|
||||
|
||||
//TODO this is a good place to create and start the TTY thread, use "tty_path" when opening device
|
||||
if (tty_open(&tty_dev) < 0) {
|
||||
fprintf(stderr, "[%s] error: opening of tty device at %s failed\n"
|
||||
"\t-> continuing in echo mode\n", NAME, tty_path);
|
||||
//return -1;
|
||||
}
|
||||
|
||||
ret = pthread_create(&tty_thread, NULL, tty_thread_func, "starting tty thread...");
|
||||
|
||||
/* loop with timeouts waiting for client connection and data*/
|
||||
|
|
|
@ -62,7 +62,7 @@ int telnet_handle_client_write(char *databuf, int *datalen);
|
|||
|
||||
|
||||
/* Opens the tty device and configures it. */
|
||||
int tty_open(struct tty_t *tty_dev, char* path);
|
||||
int tty_open(struct tty_t *tty_dev);
|
||||
/* Closes the tty device. */
|
||||
int tty_close(struct tty_t *tty_dev);
|
||||
/* Reconfigures the tty device. */
|
||||
|
|
9
tty.c
9
tty.c
|
@ -4,13 +4,20 @@
|
|||
#define NAME "tty"
|
||||
|
||||
/* Opens the tty device and configures it. */
|
||||
int tty_open(struct tty_t *tty_dev, char* path) {
|
||||
int tty_open(struct tty_t *tty_dev) {
|
||||
int fd;
|
||||
// PROPOSAL:
|
||||
// open tty device to get file descriptor @tty_dev.fd
|
||||
// setup tty device parameters @tty_dev.ttyset
|
||||
// apply settings by calling tcsetattr(fd, ttyset)
|
||||
// on success copy path to @tty_dev.path
|
||||
if ((fd = open (tty_dev->path, O_RDWR | O_NOCTTY | O_SYNC)) < 0)
|
||||
return -errno;
|
||||
else
|
||||
tty_dev->fd = fd;
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
/* Closes the tty device. */
|
||||
int tty_close(struct tty_t *tty_dev) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue