Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Synchronet
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Main
Synchronet
Commits
9078d17f
Commit
9078d17f
authored
15 years ago
by
deuce
Browse files
Options
Downloads
Patches
Plain Diff
Various stdio fixes... especiall setting raw mode and buffering stdout
and making the flush callback call fflush()
parent
2bdba1cb
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/sbbs3/sexyz.c
+73
-13
73 additions, 13 deletions
src/sbbs3/sexyz.c
with
73 additions
and
13 deletions
src/sbbs3/sexyz.c
+
73
−
13
View file @
9078d17f
...
...
@@ -332,14 +332,19 @@ void dump(BYTE* buf, int len)
}
}
int
sock_
sendbuf
(
SOCKET
s
,
void
*
buf
,
size_t
buflen
)
int
sendbuf
(
SOCKET
s
,
void
*
buf
,
size_t
buflen
)
{
size_t
sent
=
0
;
int
ret
;
fd_set
socket_set
;
for
(;;)
{
ret
=
sendsocket
(
s
,(
char
*
)
buf
+
sent
,
buflen
-
sent
);
#ifdef __unix__
if
(
stdio
)
ret
=
write
(
STDOUT_FILENO
,
(
char
*
)
buf
+
sent
,
buflen
-
sent
);
else
#endif
ret
=
sendsocket
(
s
,(
char
*
)
buf
+
sent
,
buflen
-
sent
);
if
(
ret
==
SOCKET_ERROR
)
{
switch
(
ERROR_VALUE
)
{
case
EAGAIN
:
...
...
@@ -394,7 +399,7 @@ void send_telnet_cmd(SOCKET sock, uchar cmd, uchar opt)
lprintf
(
LOG_DEBUG
,
"Sending telnet command: %s %s"
,
telnet_cmd_desc
(
buf
[
1
]),
telnet_opt_desc
(
buf
[
2
]));
if
(
sock_
sendbuf
(
sock
,
buf
,
sizeof
(
buf
))
!=
sizeof
(
buf
)
&&
debug_telnet
)
if
(
sendbuf
(
sock
,
buf
,
sizeof
(
buf
))
!=
sizeof
(
buf
)
&&
debug_telnet
)
lprintf
(
LOG_ERR
,
"FAILED"
);
}
...
...
@@ -409,18 +414,29 @@ static int recv_buffer(int timeout)
int
i
;
fd_set
socket_set
;
struct
timeval
tv
;
int
magic_errno
;
for
(;;)
{
if
(
inbuf_len
>
inbuf_pos
)
return
(
inbuf_len
-
inbuf_pos
);
#ifdef __unix__
if
(
stdio
)
if
(
stdio
)
{
i
=
read
(
STDIN_FILENO
,
inbuf
,
sizeof
(
inbuf
));
/* Look like a socket using MAGIC! */
if
(
i
==
0
)
{
i
=-
1
;
magic_errno
=
EAGAIN
;
}
}
else
#endif
{
i
=
recv
(
sock
,
inbuf
,
sizeof
(
inbuf
),
0
);
if
(
i
==
SOCKET_ERROR
)
magic_errno
=
ERROR_VALUE
;
}
if
(
i
==
SOCKET_ERROR
)
{
switch
(
ERROR_VALUE
)
{
switch
(
magic_errno
)
{
case
EAGAIN
:
case
EINTR
:
#if (EAGAIN != EWOULDBLOCK)
...
...
@@ -636,7 +652,7 @@ int send_byte(void* unused, uchar ch, unsigned timeout)
i
=
write
(
STDOUT_FILENO
,
buf
,
len
);
else
#endif
i
=
sock_
sendbuf
(
sock
,
buf
,
len
);
i
=
sendbuf
(
sock
,
buf
,
len
);
if
(
i
==
len
)
{
if
(
debug_tx
)
...
...
@@ -690,12 +706,7 @@ static void output_thread(void* arg)
buftop
=
RingBufRead
(
&
outbuf
,
buf
,
avail
);
bufbot
=
0
;
}
#ifdef __unix__
if
(
stdio
)
i
=
write
(
STDOUT_FILENO
,
(
char
*
)
buf
+
bufbot
,
buftop
-
bufbot
);
else
#endif
i
=
sock_sendbuf
(
sock
,
(
char
*
)
buf
+
bufbot
,
buftop
-
bufbot
);
i
=
sendbuf
(
sock
,
(
char
*
)
buf
+
bufbot
,
buftop
-
bufbot
);
if
(
i
==
SOCKET_ERROR
)
{
if
(
ERROR_VALUE
==
ENOTSOCK
)
lprintf
(
LOG_ERR
,
"client socket closed on send"
);
...
...
@@ -734,7 +745,8 @@ static void output_thread(void* arg)
/* Flush output buffer */
void
flush
(
void
*
unused
)
{
if
(
stdio
)
fflush
(
stdout
);
}
BOOL
is_connected
(
void
*
unused
)
...
...
@@ -1427,6 +1439,53 @@ static const char* usage=
"path = directory to receive files into
\n
"
"list = name of text file with list of filenames to send or receive
\n
"
;
#ifdef __unix__
#ifdef __unix__
struct
termios
tio_default
;
/* Initial term settings */
#endif
#ifdef NEEDS_CFMAKERAW
static
void
cfmakeraw
(
struct
termios
*
t
)
{
t
->
c_iflag
&=
~
(
IMAXBEL
|
IGNBRK
|
BRKINT
|
PARMRK
|
ISTRIP
|
INLCR
|
IGNCR
|
ICRNL
|
IXON
);
t
->
c_oflag
&=
~
OPOST
;
t
->
c_lflag
&=
~
(
ECHO
|
ECHONL
|
ICANON
|
ISIG
|
IEXTEN
);
t
->
c_cflag
&=
~
(
CSIZE
|
PARENB
);
t
->
c_cflag
|=
CS8
;
}
#endif
static
void
fixterm
(
void
)
{
tcsetattr
(
STDIN_FILENO
,
TCSANOW
,
&
tio_default
);
}
static
void
init_stdio
(
void
)
{
struct
termios
tio_raw
;
if
(
isatty
(
STDERR_FILENO
))
fclose
(
stderr
);
if
(
isatty
(
STDIN_FILENO
))
{
tcgetattr
(
STDIN_FILENO
,
&
tio_default
);
tio_raw
=
tio_default
;
/* cfmakeraw(&tio_raw); */
tio_raw
.
c_iflag
&=
~
(
IMAXBEL
|
IGNBRK
|
BRKINT
|
PARMRK
|
ISTRIP
|
INLCR
|
IGNCR
|
ICRNL
|
IXON
);
tio_raw
.
c_oflag
&=
~
OPOST
;
tio_raw
.
c_lflag
&=
~
(
ECHO
|
ECHONL
|
ICANON
|
ISIG
|
IEXTEN
);
tio_raw
.
c_cflag
&=
~
(
CSIZE
|
PARENB
);
tio_raw
.
c_cflag
|=
CS8
;
tcsetattr
(
STDIN_FILENO
,
TCSANOW
,
&
tio_raw
);
setvbuf
(
stdout
,
NULL
,
_IOFBF
,
0
);
atexit
(
fixterm
);
}
}
#endif
/***************/
/* Entry Point */
/***************/
...
...
@@ -1744,6 +1803,7 @@ int main(int argc, char **argv)
fprintf
(
statfp
,
"No socket descriptor specified, using STDIO
\n
"
);
telnet
=
FALSE
;
init_stdio
();
#else
fprintf
(
statfp
,
"!No socket descriptor specified
\n\n
"
);
fprintf
(
errfp
,
usage
,
MAX_FILE_SIZE
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment