ver 0.1.3: fixed bug with UNIX-sockets

This commit is contained in:
Edward Emelianov 2024-01-31 12:13:25 +03:00
parent 8325f811e7
commit ffdc740f5c
5 changed files with 23 additions and 10 deletions

View File

@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.0)
set(PROJ tty_term)
set(MINOR_VERSION "2")
set(MINOR_VERSION "3")
set(MID_VERSION "1")
set(MAJOR_VERSION "0")
set(VERSION "${MAJOR_VERSION}.${MID_VERSION}.${MINOR_VERSION}")
@ -9,6 +9,9 @@ project(${PROJ} VERSION ${VERSION} LANGUAGES C)
message("VER: ${VERSION}")
# options
option(DEBUG "Compile in debug mode" OFF)
# default flags
set(CMAKE_C_FLAGS_RELEASE "")
set(CMAKE_C_FLAGS_DEBUG "")
@ -20,13 +23,14 @@ set(CMAKE_COLOR_MAKEFILE ON)
aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR} SOURCES)
# cmake -DEBUG=1 -> debugging
if(DEFINED EBUG)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wextra -Wall -Werror -W")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wextra -Wall -Werror -W")
if(DEBUG)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wextra -Wall -Werror -W -Og -g3 -ggdb -fno-builtin-strlen")
set(CMAKE_BUILD_TYPE DEBUG)
set(CMAKE_VERBOSE_MAKEFILE "ON")
add_definitions(-DEBUG)
else()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3 -march=native -fdata-sections -ffunction-sections -flto=auto")
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gc-sections -flto=auto")
set(CMAKE_BUILD_TYPE RELEASE)
endif()

View File

@ -36,7 +36,7 @@ glob_pars const Gdefault = {
.speed = 9600,
.eol = "n",
.tmoutms = 100,
.port = "8N1"
.serformat = "8N1"
};
/*
@ -53,7 +53,7 @@ static myoption cmdlnopts[] = {
{"port", NEED_ARG, NULL, 'p', arg_string, APTR(&G.port), _("socket port (none for UNIX)")},
{"socket", NO_ARGS, NULL, 'S', arg_int, APTR(&G.socket), _("open socket")},
{"dumpfile",NEED_ARG, NULL, 'd', arg_string, APTR(&G.dumpfile), _("dump data to this file")},
{"format", NEED_ARG, NULL, 'f', arg_string, APTR(&G.port), _("tty format (default: 8N1)")},
{"format", NEED_ARG, NULL, 'f', arg_string, APTR(&G.serformat), _("tty format (default: 8N1)")},
end_option
};

View File

@ -31,6 +31,7 @@ typedef struct{
char *ttyname; // device name
char *eol; // end of line: \r (CR), \rn (CR+LF) or \n (LF): "r", "rn", "n"
char *port; // socket port
char *serformat; // format of serial line
} glob_pars;

10
main.c
View File

@ -59,12 +59,18 @@ int main(int argc, char **argv){
signals(0);
}
conndev.name = strdup(G->ttyname);
conndev.port = strdup(G->port);
DBG("device name: %s", conndev.name);
if(G->socket){
if(!G->port) conndev.type = DEV_UNIXSOCKET;
else conndev.type = DEV_NETSOCKET;
else{
conndev.port = strdup(G->port);
conndev.type = DEV_NETSOCKET;
}
DBG("socket port=%s, type=%d", conndev.port, conndev.type);
}else{
conndev.speed = G->speed;
conndev.port = strdup(G->serformat); // `port` of tty is serial format
DBG("speed=%d, format=%s", conndev.speed, conndev.port);
}
if(!opendev(&conndev, G->dumpfile)){
signals(0);

View File

@ -357,7 +357,7 @@ static TTY_descr2* opentty(){
goto someerr;
}
ioctl(descr->comfd, TCGETS2, &descr->tty);
if(descr->tty.c_ispeed != device->speed || descr->tty.c_ospeed != device->speed){
if(descr->tty.c_ispeed != (speed_t)device->speed || descr->tty.c_ospeed != (speed_t)device->speed){
WARN(_("Can't set speed %d, got ispeed=%d, ospeed=%d"), device->speed, descr->tty.c_ispeed, descr->tty.c_ospeed);
//goto someerr;
}
@ -381,7 +381,8 @@ int opendev(chardevice *d, char *path){
device = MALLOC(chardevice, 1);
memcpy(device, d, sizeof(chardevice));
device->name = strdup(d->name);
device->port = strdup(d->port);
if(d->port) device->port = strdup(d->port);
DBG("devtype=%d", device->type);
switch(device->type){
case DEV_TTY:
DBG("Serial");
@ -394,6 +395,7 @@ int opendev(chardevice *d, char *path){
break;
case DEV_NETSOCKET:
case DEV_UNIXSOCKET:
DBG("Socket");
device->dev = opensocket();
if(!device->dev){
WARNX("Can't open socket");