mirror of
https://github.com/eddyem/tty_term.git
synced 2026-02-01 04:45:09 +03:00
remove bug with sockets: write->send(..., MSG_NOSIGNAL)
This commit is contained in:
parent
a7f4837530
commit
fd5d3ddf8e
67
tty.c
67
tty.c
@ -1,67 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is part of the ttyterm project.
|
|
||||||
* Copyright 2020 Edward V. Emelianov <edward.emelianoff@gmail.com>.
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <stdio.h> // getchar
|
|
||||||
#include <sys/select.h>
|
|
||||||
#include "tty.h"
|
|
||||||
|
|
||||||
static int sec = 0, usec = 100; // timeout
|
|
||||||
|
|
||||||
void settimeout(int tmout){
|
|
||||||
sec = 0;
|
|
||||||
if(tmout > 999){
|
|
||||||
sec = tmout / 1000;
|
|
||||||
tmout -= sec * 1000;
|
|
||||||
}
|
|
||||||
usec = tmout * 1000L;
|
|
||||||
}
|
|
||||||
|
|
||||||
//extern FILE *fd;
|
|
||||||
|
|
||||||
int Read_tty(TTY_descr *d){
|
|
||||||
if(!d || d->comfd < 0) return 0;
|
|
||||||
size_t L = 0;
|
|
||||||
ssize_t l;
|
|
||||||
size_t length = d->bufsz;
|
|
||||||
char *ptr = d->buf;
|
|
||||||
fd_set rfds;
|
|
||||||
struct timeval tv;
|
|
||||||
int retval;
|
|
||||||
do{
|
|
||||||
l = 0;
|
|
||||||
FD_ZERO(&rfds);
|
|
||||||
FD_SET(d->comfd, &rfds);
|
|
||||||
tv.tv_sec = sec; tv.tv_usec = usec;
|
|
||||||
retval = select(d->comfd + 1, &rfds, NULL, NULL, &tv);
|
|
||||||
if(!retval) break;
|
|
||||||
if(retval < 0){
|
|
||||||
if(errno == EINTR) continue;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
if(FD_ISSET(d->comfd, &rfds)){
|
|
||||||
l = read(d->comfd, ptr, length);
|
|
||||||
if(l < 1) return -1; // disconnected
|
|
||||||
ptr += l; L += l;
|
|
||||||
length -= l;
|
|
||||||
}
|
|
||||||
}while(l && length);
|
|
||||||
d->buflen = L;
|
|
||||||
d->buf[L] = 0;
|
|
||||||
return (int)L;
|
|
||||||
}
|
|
||||||
|
|
||||||
28
tty.h
28
tty.h
@ -1,28 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is part of the ttyterm project.
|
|
||||||
* Copyright 2020 Edward V. Emelianov <edward.emelianoff@gmail.com>.
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
#ifndef TTY_H__
|
|
||||||
#define TTY_H__
|
|
||||||
|
|
||||||
#include <usefull_macros.h>
|
|
||||||
|
|
||||||
int Read_tty(TTY_descr *d);
|
|
||||||
void settimeout(int tms);
|
|
||||||
|
|
||||||
#endif // TTY_H__
|
|
||||||
@ -214,7 +214,7 @@ int SendData(chardevice *d, char *str){
|
|||||||
break;
|
break;
|
||||||
case DEV_NETSOCKET:
|
case DEV_NETSOCKET:
|
||||||
case DEV_UNIXSOCKET:
|
case DEV_UNIXSOCKET:
|
||||||
if(lplus != send(d->dev->comfd, buf, lplus, 0)) ret = 0;
|
if(lplus != send(d->dev->comfd, buf, lplus, MSG_NOSIGNAL)) ret = 0;
|
||||||
else ret = l;
|
else ret = l;
|
||||||
pthread_mutex_unlock(&d->mutex);
|
pthread_mutex_unlock(&d->mutex);
|
||||||
break;
|
break;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user