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
db78a985
Commit
db78a985
authored
4 years ago
by
Deucе
Browse files
Options
Downloads
Patches
Plain Diff
Revert last commit that used poll()
Borland hates it.
parent
76bb4aec
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/xpdev/multisock.c
+27
-30
27 additions, 30 deletions
src/xpdev/multisock.c
with
27 additions
and
30 deletions
src/xpdev/multisock.c
+
27
−
30
View file @
db78a985
...
...
@@ -4,7 +4,6 @@
#include
<stdlib.h>
#include
<string.h>
#include
"gen_defs.h"
#include
"genwrap.h"
#include
"sockwrap.h"
#include
"dirwrap.h"
#include
"multisock.h"
...
...
@@ -256,18 +255,22 @@ static void btox(char *hexstr, const char *srcbuf, size_t srcbuflen, size_t hexs
static
BOOL
read_socket
(
SOCKET
sock
,
char
*
buffer
,
size_t
len
,
int
(
*
lprintf
)(
int
level
,
const
char
*
fmt
,
...))
{
fd_set
socket_set
;
struct
timeval
tv
;
size_t
i
;
int
j
,
rd
;
unsigned
char
ch
;
char
err
[
128
];
struct
pollfd
pfd
;
for
(
i
=
0
;
i
<
len
;
i
++
)
{
pfd
.
fd
=
sock
;
pfd
.
events
=
POLLIN
;
pfd
.
revents
=
0
;
FD_ZERO
(
&
socket_set
);
FD_SET
(
sock
,
&
socket_set
);
if
((
j
=
poll
(
&
pfd
,
1
,
1000
))
>
0
)
{
// We'll wait 1 secs to read from the socket.
tv
.
tv_sec
=
1
;
tv
.
tv_usec
=
0
;
if
((
j
=
select
(
sock
+
1
,
&
socket_set
,
NULL
,
NULL
,
&
tv
))
>
0
)
{
rd
=
recv
(
sock
,
&
ch
,
1
,
0
);
if
(
rd
==
0
)
{
lprintf
(
LOG_WARNING
,
"%04d multisock read_socket() - remote closed the connection"
,
sock
);
...
...
@@ -286,7 +289,7 @@ static BOOL read_socket(SOCKET sock, char *buffer, size_t len, int (*lprintf)(in
return
FALSE
;
}
else
{
lprintf
(
LOG_WARNING
,
"%04d multisock read_socket() -
poll
() returned [%d] with error [%s]."
,
sock
,
j
,
socket_strerror
(
socket_errno
,
err
,
sizeof
(
err
)));
lprintf
(
LOG_WARNING
,
"%04d multisock read_socket() -
select
() returned [%d] with error [%s]."
,
sock
,
j
,
socket_strerror
(
socket_errno
,
err
,
sizeof
(
err
)));
return
FALSE
;
}
}
...
...
@@ -321,50 +324,44 @@ static BOOL read_socket_line(SOCKET sock, char *buffer, size_t buflen, int (*lpr
SOCKET
DLLCALL
xpms_accept
(
struct
xpms_set
*
xpms_set
,
union
xp_sockaddr
*
addr
,
socklen_t
*
addrlen
,
unsigned
int
timeout
,
uint32_t
flags
,
void
**
cb_data
)
{
fd_set
read_fs
;
size_t
i
;
struct
timeval
tv
;
struct
timeval
*
tvp
;
SOCKET
max_sock
=
0
;
SOCKET
ret
;
char
hapstr
[
128
];
char
haphex
[
256
];
char
*
p
,
*
tok
;
long
l
;
void
*
vp
;
struct
pollfd
*
pfds
;
int
timeo
;
nfds_t
cnt
=
0
;
if
(
xpms_set
->
sock_count
<
1
)
{
// Just sleep()..
SLEEP
(
timeout
);
return
INVALID_SOCKET
;
}
pfds
=
malloc
(
sizeof
(
struct
pollfd
)
*
xpms_set
->
sock_count
);
if
(
pfds
==
NULL
)
return
INVALID_SOCKET
;
FD_ZERO
(
&
read_fs
);
for
(
i
=
0
;
i
<
xpms_set
->
sock_count
;
i
++
)
{
if
(
xpms_set
->
socks
[
i
].
sock
==
INVALID_SOCKET
)
continue
;
pfds
[
cnt
].
fd
=
xpms_set
->
socks
[
i
].
sock
;
pfds
[
cnt
].
events
=
POLLIN
;
pfds
[
cnt
].
revents
=
0
;
cnt
++
;
FD_SET
(
xpms_set
->
socks
[
i
].
sock
,
&
read_fs
);
if
(
xpms_set
->
socks
[
i
].
sock
>=
max_sock
)
max_sock
=
xpms_set
->
socks
[
i
].
sock
+
1
;
}
if
(
timeout
==
XPMS_FOREVER
)
timeo
=
-
1
;
else
timeo
=
timeout
;
switch
(
poll
(
pfds
,
cnt
,
timeo
))
{
tvp
=
NULL
;
else
{
tv
.
tv_sec
=
timeout
/
1000
;
tv
.
tv_usec
=
(
timeout
%
1000
)
*
1000
;
tvp
=&
tv
;
}
switch
(
select
(
max_sock
,
&
read_fs
,
NULL
,
NULL
,
tvp
))
{
case
0
:
return
INVALID_SOCKET
;
case
-
1
:
return
SOCKET_ERROR
;
default:
for
(
i
=
0
,
cnt
=
0
;
i
<
xpms_set
->
sock_count
;
i
++
)
{
for
(
i
=
0
;
i
<
xpms_set
->
sock_count
;
i
++
)
{
if
(
xpms_set
->
socks
[
i
].
sock
==
INVALID_SOCKET
)
continue
;
if
(
pfds
[
cnt
++
].
revents
&
POLLIN
)
{
if
(
FD_ISSET
(
xpms_set
->
socks
[
i
].
sock
,
&
read_fs
)
)
{
if
(
cb_data
)
*
cb_data
=
xpms_set
->
socks
[
i
].
cb_data
;
ret
=
accept
(
xpms_set
->
socks
[
i
].
sock
,
&
addr
->
addr
,
addrlen
);
...
...
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