Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
LSH
lsh
Commits
8ad728c6
Commit
8ad728c6
authored
Jan 04, 1999
by
Niels Möller
Browse files
* io.c (write_raw): New function.
(write_raw_with_poll): -"- Rev: src/io.c:1.40 Rev: src/io.h:1.26
parent
5329136b
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/io.c
View file @
8ad728c6
...
...
@@ -234,7 +234,7 @@ static int do_read(struct abstract_read **r, UINT32 length, UINT8 *buffer)
case
EWOULDBLOCK
:
/* aka EAGAIN */
return
0
;
case
EPIPE
:
w
error
(
"io.c: read() returned EPIPE! Treating it as EOF.
\n
"
);
w
write
(
"io.c: read() returned EPIPE! Treating it as EOF.
\n
"
);
return
A_EOF
;
default:
werror
(
"io.c: do_read: read() failed (errno %d), %s
\n
"
,
...
...
@@ -358,7 +358,7 @@ static void listen_callback(struct lsh_fd *fd)
res
=
FD_CALLBACK
(
self
->
callback
,
conn
);
if
(
LSH_ACTIONP
(
res
))
{
w
error
(
"Strange: Accepted a connection, "
w
write
(
"Strange: Accepted a connection, "
"but failed before writing anything.
\n
"
);
close_fd
(
fd
,
(
LSH_FAILUREP
(
res
)
?
CLOSE_PROTOCOL_FAILURE
...
...
@@ -375,7 +375,7 @@ static void connect_callback(struct lsh_fd *fd)
if
(
LSH_ACTIONP
(
res
))
{
w
error
(
"Strange: Connected, "
w
write
(
"Strange: Connected, "
"but failed before writing anything.
\n
"
);
}
else
...
...
@@ -535,6 +535,70 @@ get_inaddr(struct sockaddr_in * addr,
return
1
;
}
/* For fd:s in blocking mode. */
int
write_raw
(
int
fd
,
UINT32
length
,
UINT8
*
data
)
{
while
(
length
)
{
int
written
=
write
(
fd
,
data
,
length
);
if
(
written
<
0
)
switch
(
errno
)
{
case
EINTR
:
case
EAGAIN
:
continue
;
default:
return
0
;
}
length
-=
written
;
data
+=
written
;
}
return
1
;
}
int
write_raw_with_poll
(
int
fd
,
UINT32
length
,
UINT8
*
data
)
{
while
(
length
)
{
struct
pollfd
pfd
;
int
res
;
int
written
;
pfd
.
fd
=
fd
;
pfd
.
events
=
POLLOUT
;
res
=
poll
(
&
pfd
,
1
,
-
1
);
if
(
res
<
0
)
switch
(
errno
)
{
case
EINTR
:
case
EAGAIN
:
continue
;
default:
return
0
;
}
written
=
write
(
fd
,
data
,
length
);
if
(
written
<
0
)
switch
(
errno
)
{
case
EINTR
:
case
EAGAIN
:
continue
;
default:
return
0
;
}
length
-=
written
;
data
+=
written
;
}
return
1
;
}
void
io_set_nonblocking
(
int
fd
)
{
if
(
fcntl
(
fd
,
F_SETFL
,
O_NONBLOCK
)
<
0
)
...
...
src/io.h
View file @
8ad728c6
...
...
@@ -159,6 +159,9 @@ int get_inaddr(struct sockaddr_in * addr,
const
char
*
service
,
const
char
*
protocol
);
int
write_raw
(
int
fd
,
UINT32
length
,
UINT8
*
data
);
int
write_raw_with_poll
(
int
fd
,
UINT32
length
,
UINT8
*
data
);
void
io_set_nonblocking
(
int
fd
);
void
io_set_close_on_exec
(
int
fd
);
void
io_init_fd
(
int
fd
);
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment