Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
pike
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
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
pikelang
pike
Commits
2bad2b7e
Commit
2bad2b7e
authored
Sep 16, 1997
by
Fredrik Hübinette (Hubbe)
Browse files
Options
Downloads
Patches
Plain Diff
socketpair_ultra optimized
Rev: src/modules/files/file.c:1.54
parent
da6d1259
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/modules/files/file.c
+56
-26
56 additions, 26 deletions
src/modules/files/file.c
with
56 additions
and
26 deletions
src/modules/files/file.c
+
56
−
26
View file @
2bad2b7e
...
@@ -6,7 +6,7 @@
...
@@ -6,7 +6,7 @@
#define READ_BUFFER 8192
#define READ_BUFFER 8192
#include
"global.h"
#include
"global.h"
RCSID
(
"$Id: file.c,v 1.5
3
1997/09/16 0
6:03:21
hubbe Exp $"
);
RCSID
(
"$Id: file.c,v 1.5
4
1997/09/16 0
7:32:42
hubbe Exp $"
);
#include
"interpret.h"
#include
"interpret.h"
#include
"svalue.h"
#include
"svalue.h"
#include
"stralloc.h"
#include
"stralloc.h"
...
@@ -977,8 +977,10 @@ static void file_set_buffer(INT32 args)
...
@@ -977,8 +977,10 @@ static void file_set_buffer(INT32 args)
extern
int
errno
;
extern
int
errno
;
int
socketpair
(
int
family
,
int
type
,
int
protocol
,
int
sv
[
2
])
int
socketpair
(
int
family
,
int
type
,
int
protocol
,
int
sv
[
2
])
{
{
static
int
fd
=-
1
;
static
struct
sockaddr_in
my_addr
;
struct
sockaddr_in
addr
,
addr2
;
struct
sockaddr_in
addr
,
addr2
;
int
len
,
fd
;
int
len
;
MEMSET
((
char
*
)
&
addr
,
0
,
sizeof
(
struct
sockaddr_in
));
MEMSET
((
char
*
)
&
addr
,
0
,
sizeof
(
struct
sockaddr_in
));
...
@@ -989,39 +991,69 @@ int socketpair(int family, int type, int protocol, int sv[2])
...
@@ -989,39 +991,69 @@ int socketpair(int family, int type, int protocol, int sv[2])
return
-
1
;
return
-
1
;
}
}
if
(
fd
==-
1
)
{
if
((
fd
=
socket
(
AF_INET
,
SOCK_STREAM
,
0
))
<
0
)
return
-
1
;
if
((
fd
=
socket
(
AF_INET
,
SOCK_STREAM
,
0
))
<
0
)
return
-
1
;
if
((
sv
[
1
]
=
socket
(
AF_INET
,
SOCK_STREAM
,
0
))
<
0
)
return
-
1
;
/* I wonder what is most common a loopback on ip# 127.0.0.1 or
/* I wonder what is most common a loopback on ip# 127.0.0.1 or
* a loopback with the name "localhost"?
* a loopback with the name "localhost"?
* Let's hope those few people who doesn't have socketpair has
* Let's hope those few people who doesn't have socketpair has
* a loopback on 127.0.0.1
* a loopback on 127.0.0.1
*/
*/
addr
.
sin_addr
.
s_addr
=
htonl
(
INADDR_ANY
);
my_
addr
.
sin_addr
.
s_addr
=
htonl
(
INADDR_ANY
);
addr
.
sin_port
=
htons
(
0
);
my_
addr
.
sin_port
=
htons
(
0
);
/* Bind our sockets on any port */
/* Bind our sockets on any port */
if
(
bind
(
fd
,
(
struct
sockaddr
*
)
&
addr
,
sizeof
(
addr
))
<
0
)
return
-
1
;
if
(
bind
(
fd
,
(
struct
sockaddr
*
)
&
addr
,
sizeof
(
addr
))
<
0
)
{
close
(
fd
);
fd
=-
1
;
return
-
1
;
}
/* Check what ports we got.. */
/* Check what ports we got.. */
len
=
sizeof
(
addr
);
len
=
sizeof
(
my_addr
);
if
(
getsockname
(
fd
,(
struct
sockaddr
*
)
&
addr
,
&
len
)
<
0
)
return
-
1
;
if
(
getsockname
(
fd
,(
struct
sockaddr
*
)
&
my_addr
,
&
len
)
<
0
)
{
addr
.
sin_addr
.
s_addr
=
inet_addr
(
"127.0.0.1"
);
close
(
fd
);
fd
=-
1
;
return
-
1
;
}
/* Listen to connections on our new socket */
/* Listen to connections on our new socket */
if
(
listen
(
fd
,
3
)
<
0
)
return
-
1
;
if
(
listen
(
fd
,
5
)
<
0
)
{
close
(
fd
);
fd
=-
1
;
return
-
1
;
}
}
if
((
sv
[
1
]
=
socket
(
AF_INET
,
SOCK_STREAM
,
0
))
<
0
)
return
-
1
;
addr
.
sin_addr
.
s_addr
=
inet_addr
(
"127.0.0.1"
);
/* set_nonblocking(sv[1],1); */
/* set_nonblocking(sv[1],1); */
/* Connect */
if
(
connect
(
sv
[
1
],
(
struct
sockaddr
*
)
&
my_addr
,
sizeof
(
my_addr
))
<
0
)
if
(
connect
(
sv
[
1
],
(
struct
sockaddr
*
)
&
addr
,
sizeof
(
addr
))
<
0
)
return
-
1
;
{
int
tmp2
;
for
(
tmp2
=
0
;
tmp2
<
20
;
tmp2
++
)
{
int
tmp
;
len
=
sizeof
(
addr
);
tmp
=
accept
(
fd
,(
struct
sockaddr
*
)
&
addr
,
&
len
);
if
(
tmp
!=-
1
)
close
(
tmp
);
if
(
connect
(
sv
[
1
],
(
struct
sockaddr
*
)
&
my_addr
,
sizeof
(
my_addr
))
>=
0
)
break
;
}
if
(
tmp2
>=
20
)
return
-
1
;
}
len
=
sizeof
(
addr
);
len
=
sizeof
(
addr
);
if
(
getsockname
(
sv
[
1
],(
struct
sockaddr
*
)
&
addr2
,
&
len
)
<
0
)
return
-
1
;
if
(
getsockname
(
sv
[
1
],(
struct
sockaddr
*
)
&
addr2
,
&
len
)
<
0
)
return
-
1
;
/* Accept connection
/* Accept connection
* Make sure this connection was our OWN connection,
* Make sure this connection was our OWN connection,
* otherwise some wizeguy could interfere with our
* otherwise some wizeguy could interfere with our
...
@@ -1042,8 +1074,6 @@ int socketpair(int family, int type, int protocol, int sv[2])
...
@@ -1042,8 +1074,6 @@ int socketpair(int family, int type, int protocol, int sv[2])
addr2
.
sin_addr
.
s_addr
!=
addr
.
sin_addr
.
s_addr
||
addr2
.
sin_addr
.
s_addr
!=
addr
.
sin_addr
.
s_addr
||
addr2
.
sin_port
!=
addr
.
sin_port
);
addr2
.
sin_port
!=
addr
.
sin_port
);
if
(
close
(
fd
)
<
0
)
return
-
1
;
/* set_nonblocking(sv[1],0); */
/* set_nonblocking(sv[1],0); */
return
0
;
return
0
;
...
...
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