Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
B
babeld
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
babeld
Commits
dcd1dba6
Commit
dcd1dba6
authored
Feb 10, 2016
by
Juliusz Chroboczek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use a structure for local sockets.
parent
2f3ca807
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
40 additions
and
33 deletions
+40
-33
babeld.c
babeld.c
+7
-7
local.c
local.c
+25
-23
local.h
local.h
+8
-3
No files found.
babeld.c
View file @
dcd1dba6
...
...
@@ -619,8 +619,8 @@ main(int argc, char **argv)
maxfd
=
MAX
(
maxfd
,
local_server_socket
);
}
for
(
i
=
0
;
i
<
num_local_sockets
;
i
++
)
{
FD_SET
(
local_sockets
[
i
],
&
readfds
);
maxfd
=
MAX
(
maxfd
,
local_sockets
[
i
]);
FD_SET
(
local_sockets
[
i
]
.
fd
,
&
readfds
);
maxfd
=
MAX
(
maxfd
,
local_sockets
[
i
]
.
fd
);
}
#endif
rc
=
select
(
maxfd
+
1
,
&
readfds
,
NULL
,
NULL
,
&
tv
);
...
...
@@ -677,15 +677,15 @@ main(int argc, char **argv)
i
=
0
;
while
(
i
<
num_local_sockets
)
{
if
(
FD_ISSET
(
local_sockets
[
i
],
&
readfds
))
{
rc
=
local_read
(
local_sockets
[
i
]);
if
(
FD_ISSET
(
local_sockets
[
i
]
.
fd
,
&
readfds
))
{
rc
=
local_read
(
&
local_sockets
[
i
]);
if
(
rc
<=
0
)
{
if
(
rc
<
0
)
{
if
(
errno
==
EINTR
)
continue
;
perror
(
"read(local_socket)"
);
}
close
(
local_sockets
[
i
]);
close
(
local_sockets
[
i
]
.
fd
);
local_sockets
[
i
]
=
local_sockets
[
--
num_local_sockets
];
continue
;
}
...
...
@@ -917,8 +917,8 @@ accept_local_connections(fd_set *readfds)
return
-
1
;
}
local_sockets
[
num_local_sockets
++
]
=
s
;
local_notify_all_1
(
s
);
local_sockets
[
num_local_sockets
++
]
.
fd
=
s
;
local_notify_all_1
(
&
local_sockets
[
num_local_sockets
-
1
]
);
return
1
;
}
...
...
local.c
View file @
dcd1dba6
...
...
@@ -44,18 +44,19 @@ int dummy;
#else
int
local_server_socket
=
-
1
,
local_sockets
[
MAX_LOCAL_SOCKETS
];
int
local_server_socket
=
-
1
;
struct
local_socket
local_sockets
[
MAX_LOCAL_SOCKETS
];
int
num_local_sockets
=
0
;
int
local_server_port
=
-
1
;
int
local_read
(
int
s
)
local_read
(
struct
local_socket
*
s
)
{
int
rc
;
char
buf
[
500
];
/* Ignore anything that comes in, except for EOF */
rc
=
read
(
s
,
buf
,
500
);
rc
=
read
(
s
->
fd
,
buf
,
500
);
if
(
rc
<=
0
)
return
rc
;
...
...
@@ -95,7 +96,7 @@ write_timeout(int fd, const void *buf, int len)
}
static
void
local_notify_self_1
(
int
s
)
local_notify_self_1
(
struct
local_socket
*
s
)
{
char
buf
[
512
];
char
host
[
64
];
...
...
@@ -112,13 +113,13 @@ local_notify_self_1(int s)
if
(
rc
<
0
||
rc
>=
512
)
goto
fail
;
rc
=
write_timeout
(
s
,
buf
,
rc
);
rc
=
write_timeout
(
s
->
fd
,
buf
,
rc
);
if
(
rc
<
0
)
goto
fail
;
return
;
fail:
shutdown
(
s
,
1
);
shutdown
(
s
->
fd
,
1
);
return
;
}
...
...
@@ -134,7 +135,8 @@ local_kind(int kind)
}
static
void
local_notify_neighbour_1
(
int
s
,
struct
neighbour
*
neigh
,
int
kind
)
local_notify_neighbour_1
(
struct
local_socket
*
s
,
struct
neighbour
*
neigh
,
int
kind
)
{
char
buf
[
512
],
rttbuf
[
64
];
int
rc
;
...
...
@@ -165,13 +167,13 @@ local_notify_neighbour_1(int s, struct neighbour *neigh, int kind)
if
(
rc
<
0
||
rc
>=
512
)
goto
fail
;
rc
=
write_timeout
(
s
,
buf
,
rc
);
rc
=
write_timeout
(
s
->
fd
,
buf
,
rc
);
if
(
rc
<
0
)
goto
fail
;
return
;
fail:
shutdown
(
s
,
1
);
shutdown
(
s
->
fd
,
1
);
return
;
}
...
...
@@ -180,11 +182,11 @@ local_notify_neighbour(struct neighbour *neigh, int kind)
{
int
i
;
for
(
i
=
0
;
i
<
num_local_sockets
;
i
++
)
local_notify_neighbour_1
(
local_sockets
[
i
],
neigh
,
kind
);
local_notify_neighbour_1
(
&
local_sockets
[
i
],
neigh
,
kind
);
}
static
void
local_notify_xroute_1
(
int
s
,
struct
xroute
*
xroute
,
int
kind
)
local_notify_xroute_1
(
struct
local_socket
*
s
,
struct
xroute
*
xroute
,
int
kind
)
{
char
buf
[
512
];
int
rc
;
...
...
@@ -200,13 +202,13 @@ local_notify_xroute_1(int s, struct xroute *xroute, int kind)
if
(
rc
<
0
||
rc
>=
512
)
goto
fail
;
rc
=
write_timeout
(
s
,
buf
,
rc
);
rc
=
write_timeout
(
s
->
fd
,
buf
,
rc
);
if
(
rc
<
0
)
goto
fail
;
return
;
fail:
shutdown
(
s
,
1
);
shutdown
(
s
->
fd
,
1
);
return
;
}
...
...
@@ -215,11 +217,11 @@ local_notify_xroute(struct xroute *xroute, int kind)
{
int
i
;
for
(
i
=
0
;
i
<
num_local_sockets
;
i
++
)
local_notify_xroute_1
(
local_sockets
[
i
],
xroute
,
kind
);
local_notify_xroute_1
(
&
local_sockets
[
i
],
xroute
,
kind
);
}
static
void
local_notify_route_1
(
int
s
,
struct
babel_route
*
route
,
int
kind
)
local_notify_route_1
(
struct
local_socket
*
s
,
struct
babel_route
*
route
,
int
kind
)
{
char
buf
[
512
];
int
rc
;
...
...
@@ -243,13 +245,13 @@ local_notify_route_1(int s, struct babel_route *route, int kind)
if
(
rc
<
0
||
rc
>=
512
)
goto
fail
;
rc
=
write_timeout
(
s
,
buf
,
rc
);
rc
=
write_timeout
(
s
->
fd
,
buf
,
rc
);
if
(
rc
<
0
)
goto
fail
;
return
;
fail:
shutdown
(
s
,
1
);
shutdown
(
s
->
fd
,
1
);
return
;
}
...
...
@@ -258,11 +260,11 @@ local_notify_route(struct babel_route *route, int kind)
{
int
i
;
for
(
i
=
0
;
i
<
num_local_sockets
;
i
++
)
local_notify_route_1
(
local_sockets
[
i
],
route
,
kind
);
local_notify_route_1
(
&
local_sockets
[
i
],
route
,
kind
);
}
void
local_notify_all_1
(
int
s
)
local_notify_all_1
(
struct
local_socket
*
s
)
{
int
rc
;
struct
neighbour
*
neigh
;
...
...
@@ -271,14 +273,14 @@ local_notify_all_1(int s)
struct
xroute_stream
*
xroutes
;
struct
route_stream
*
routes
;
rc
=
write_timeout
(
s
,
header
,
strlen
(
header
));
rc
=
write_timeout
(
s
->
fd
,
header
,
strlen
(
header
));
if
(
rc
<
0
)
goto
fail
;
rc
=
snprintf
(
buf
,
512
,
"version %s
\n
"
,
BABELD_VERSION
);
if
(
rc
<
0
||
rc
>=
512
)
goto
fail
;
rc
=
write_timeout
(
s
,
buf
,
rc
);
rc
=
write_timeout
(
s
->
fd
,
buf
,
rc
);
if
(
rc
<
0
)
goto
fail
;
...
...
@@ -309,13 +311,13 @@ local_notify_all_1(int s)
route_stream_done
(
routes
);
}
rc
=
write_timeout
(
s
,
"done
\n
"
,
5
);
rc
=
write_timeout
(
s
->
fd
,
"done
\n
"
,
5
);
if
(
rc
<
0
)
goto
fail
;
return
;
fail:
shutdown
(
s
,
1
);
shutdown
(
s
->
fd
,
1
);
return
;
}
...
...
local.h
View file @
dcd1dba6
...
...
@@ -34,15 +34,20 @@ struct xroute;
#define MAX_LOCAL_SOCKETS 4
#endif
extern
int
local_server_socket
,
local_sockets
[
MAX_LOCAL_SOCKETS
];
struct
local_socket
{
int
fd
;
};
extern
int
local_server_socket
;
extern
struct
local_socket
local_sockets
[
MAX_LOCAL_SOCKETS
];
extern
int
num_local_sockets
;
extern
int
local_server_port
;
int
local_read
(
int
s
);
int
local_read
(
struct
local_socket
*
s
);
void
local_notify_neighbour
(
struct
neighbour
*
neigh
,
int
kind
);
void
local_notify_xroute
(
struct
xroute
*
xroute
,
int
kind
);
void
local_notify_route
(
struct
babel_route
*
route
,
int
kind
);
void
local_notify_all_1
(
int
s
);
void
local_notify_all_1
(
struct
local_socket
*
s
);
#else
...
...
Write
Preview
Markdown
is supported
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