Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
fanout
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Gerhard Gonter
fanout
Commits
c3fffb4d
Commit
c3fffb4d
authored
Dec 12, 2014
by
Travis Glenn Hansen
Browse files
Options
Downloads
Plain Diff
Merge pull request #16 from Barthalion/nitpicks
Minor fixes/style changes
parents
289a9ba4
dac784fa
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
fanout.c
+15
-21
15 additions, 21 deletions
fanout.c
with
15 additions
and
21 deletions
fanout.c
+
15
−
21
View file @
c3fffb4d
...
@@ -73,7 +73,7 @@ int channel_has_subscription (struct channel *c);
...
@@ -73,7 +73,7 @@ int channel_has_subscription (struct channel *c);
struct
channel
*
get_channel
(
const
char
*
channel_name
);
struct
channel
*
get_channel
(
const
char
*
channel_name
);
void
remove_channel
(
struct
channel
*
c
);
void
remove_channel
(
struct
channel
*
c
);
void
destroy_channel
(
struct
channel
*
c
);
void
destroy_channel
(
struct
channel
*
c
);
u_int
channel_count
();
u_int
channel_count
(
void
);
struct
client
*
get_client
(
int
fd
);
struct
client
*
get_client
(
int
fd
);
...
@@ -82,14 +82,14 @@ void shutdown_client (struct client *c);
...
@@ -82,14 +82,14 @@ void shutdown_client (struct client *c);
void
destroy_client
(
struct
client
*
c
);
void
destroy_client
(
struct
client
*
c
);
void
client_write
(
struct
client
*
c
,
const
char
*
data
);
void
client_write
(
struct
client
*
c
,
const
char
*
data
);
void
client_process_input_buffer
(
struct
client
*
c
);
void
client_process_input_buffer
(
struct
client
*
c
);
u_int
client_count
();
u_int
client_count
(
void
);
struct
subscription
*
get_subscription
(
struct
client
*
c
,
struct
subscription
*
get_subscription
(
struct
client
*
c
,
struct
channel
*
channel
);
struct
channel
*
channel
);
void
remove_subscription
(
struct
subscription
*
s
);
void
remove_subscription
(
struct
subscription
*
s
);
void
destroy_subscription
(
struct
subscription
*
s
);
void
destroy_subscription
(
struct
subscription
*
s
);
u_int
subscription_count
();
u_int
subscription_count
(
void
);
void
announce
(
const
char
*
channel_name
,
const
char
*
message
);
void
announce
(
const
char
*
channel_name
,
const
char
*
message
);
...
@@ -152,7 +152,7 @@ int main (int argc, char *argv[])
...
@@ -152,7 +152,7 @@ int main (int argc, char *argv[])
hints
.
ai_flags
=
AI_PASSIVE
|
AI_ADDRCONFIG
;
hints
.
ai_flags
=
AI_PASSIVE
|
AI_ADDRCONFIG
;
hints
.
ai_socktype
=
SOCK_STREAM
;
hints
.
ai_socktype
=
SOCK_STREAM
;
int
e
;
int
e
;
int
epollfd
,
efd
,
n
,
res
;
int
epollfd
,
efd
,
res
;
int
portno
=
1986
;
int
portno
=
1986
;
int
optval
;
int
optval
;
socklen_t
optlen
=
sizeof
(
optval
);
socklen_t
optlen
=
sizeof
(
optval
);
...
@@ -254,7 +254,6 @@ fs.file-max=100000\n");
...
@@ -254,7 +254,6 @@ fs.file-max=100000\n");
printf
(
" --help show this info and e\
printf
(
" --help show this info and e\
xit
\n
"
);
xit
\n
"
);
exit
(
EXIT_SUCCESS
);
exit
(
EXIT_SUCCESS
);
break
;
//client-limit
//client-limit
case
6
:
case
6
:
client_limit
=
atoi
(
optarg
);
client_limit
=
atoi
(
optarg
);
...
@@ -377,7 +376,7 @@ xit\n");
...
@@ -377,7 +376,7 @@ xit\n");
if
((
epollfd
=
epoll_create
(
nfds
))
<
0
)
if
((
epollfd
=
epoll_create
(
nfds
))
<
0
)
fanout_error
(
"ERROR creating epoll instance"
);
fanout_error
(
"ERROR creating epoll instance"
);
for
(
n
=
0
;
n
<
nfds
;
n
++
)
{
for
(
int
n
=
0
;
n
<
nfds
;
n
++
)
{
if
(
epoll_ctl
(
epollfd
,
EPOLL_CTL_ADD
,
fds
[
n
].
data
.
fd
,
&
fds
[
n
])
==
-
1
)
{
if
(
epoll_ctl
(
epollfd
,
EPOLL_CTL_ADD
,
fds
[
n
].
data
.
fd
,
&
fds
[
n
])
==
-
1
)
{
fanout_error
(
"epoll_ctl: srvsock"
);
fanout_error
(
"epoll_ctl: srvsock"
);
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
...
@@ -511,7 +510,7 @@ xit\n");
...
@@ -511,7 +510,7 @@ xit\n");
continue
;
continue
;
}
}
for
(
n
=
0
;
n
<
nevents
;
n
++
)
{
for
(
int
n
=
0
;
n
<
nevents
;
n
++
)
{
// new connection
// new connection
efd
=
events
[
n
].
data
.
fd
;
efd
=
events
[
n
].
data
.
fd
;
fanout_debug
(
3
,
"processing event %d of %d
\n
"
,
(
n
+
1
),
fanout_debug
(
3
,
"processing event %d of %d
\n
"
,
(
n
+
1
),
...
@@ -519,8 +518,8 @@ xit\n");
...
@@ -519,8 +518,8 @@ xit\n");
fanout_debug
(
3
,
"current event fd %d
\n
"
,
efd
);
fanout_debug
(
3
,
"current event fd %d
\n
"
,
efd
);
int
newconnection
=
0
;
int
newconnection
=
0
;
for
(
n
=
0
;
n
<
nfds
;
n
++
)
{
for
(
int
m
=
0
;
m
<
nfds
;
m
++
)
{
if
(
efd
==
fds
[
n
].
data
.
fd
)
{
if
(
efd
==
fds
[
m
].
data
.
fd
)
{
newconnection
=
1
;
newconnection
=
1
;
break
;
break
;
}
}
...
@@ -637,7 +636,7 @@ resetting counter\n");
...
@@ -637,7 +636,7 @@ resetting counter\n");
}
//end for
}
//end for
}
//end while (1)
}
//end while (1)
for
(
n
=
0
;
n
<
nfds
;
n
++
)
{
for
(
int
n
=
0
;
n
<
nfds
;
n
++
)
{
close
(
fds
[
n
].
data
.
fd
);
close
(
fds
[
n
].
data
.
fd
);
}
}
return
0
;
return
0
;
...
@@ -657,8 +656,7 @@ int is_numeric (char *str)
...
@@ -657,8 +656,7 @@ int is_numeric (char *str)
int
strcpos
(
const
char
*
haystack
,
const
char
c
)
int
strcpos
(
const
char
*
haystack
,
const
char
c
)
{
{
int
i
;
for
(
int
i
=
0
;
i
<=
strlen
(
haystack
);
i
++
)
{
for
(
i
=
0
;
i
<=
strlen
(
haystack
);
i
++
)
{
if
(
haystack
[
i
]
==
c
)
if
(
haystack
[
i
]
==
c
)
return
i
;
return
i
;
}
}
...
@@ -710,9 +708,7 @@ void clear_socket_buffer (int sock)
...
@@ -710,9 +708,7 @@ void clear_socket_buffer (int sock)
{
{
char
buffer
[
1025
];
char
buffer
[
1025
];
for
(;;)
{
for
(;;)
{
int
res
;
int
res
=
read
(
sock
,
buffer
,
1024
);
res
=
read
(
sock
,
buffer
,
1024
);
if
(
res
<
0
)
{
if
(
res
<
0
)
{
fanout_debug
(
0
,
"%s
\n
"
,
"failed clearing socket buffer"
);
fanout_debug
(
0
,
"%s
\n
"
,
"failed clearing socket buffer"
);
...
@@ -921,9 +917,9 @@ void shutdown_client (struct client *c)
...
@@ -921,9 +917,9 @@ void shutdown_client (struct client *c)
struct
subscription
*
subscription_i
=
subscription_head
;
struct
subscription
*
subscription_i
=
subscription_head
;
while
(
subscription_i
!=
NULL
)
{
while
(
subscription_i
!=
NULL
)
{
struct
subscription
*
subscription_tmp
;
struct
subscription
*
subscription_tmp
=
subscription_i
;
subscription_tmp
=
subscription_i
;
subscription_i
=
subscription_i
->
next
;
subscription_i
=
subscription_i
->
next
;
if
(
c
==
subscription_tmp
->
client
)
if
(
c
==
subscription_tmp
->
client
)
unsubscribe
(
c
,
subscription_tmp
->
channel
->
name
);
unsubscribe
(
c
,
subscription_tmp
->
channel
->
name
);
}
}
...
@@ -953,8 +949,7 @@ void client_write (struct client *c, const char *data)
...
@@ -953,8 +949,7 @@ void client_write (struct client *c, const char *data)
c
->
output_buffer
=
str_append
(
c
->
output_buffer
,
data
);
c
->
output_buffer
=
str_append
(
c
->
output_buffer
,
data
);
while
(
strlen
(
c
->
output_buffer
)
>
0
)
{
while
(
strlen
(
c
->
output_buffer
)
>
0
)
{
int
sent
;
int
sent
=
send
(
c
->
fd
,
c
->
output_buffer
,
strlen
(
c
->
output_buffer
),
sent
=
send
(
c
->
fd
,
c
->
output_buffer
,
strlen
(
c
->
output_buffer
),
MSG_NOSIGNAL
);
MSG_NOSIGNAL
);
if
(
sent
==
-
1
)
if
(
sent
==
-
1
)
break
;
break
;
...
@@ -977,8 +972,7 @@ void client_process_input_buffer (struct client *c)
...
@@ -977,8 +972,7 @@ void client_process_input_buffer (struct client *c)
fanout_debug
(
3
,
"full buffer
\n\n
%s
\n\n
"
,
c
->
input_buffer
);
fanout_debug
(
3
,
"full buffer
\n\n
%s
\n\n
"
,
c
->
input_buffer
);
while
((
i
=
strcpos
(
c
->
input_buffer
,
'\n'
))
>=
0
)
{
while
((
i
=
strcpos
(
c
->
input_buffer
,
'\n'
))
>=
0
)
{
char
*
line
;
char
*
line
=
substr
(
c
->
input_buffer
,
0
,
i
-
1
);
line
=
substr
(
c
->
input_buffer
,
0
,
i
-
1
);
fanout_debug
(
3
,
"buffer has a newline at char %d
\n
"
,
i
);
fanout_debug
(
3
,
"buffer has a newline at char %d
\n
"
,
i
);
fanout_debug
(
3
,
"line is %d chars: %s
\n
"
,
(
u_int
)
strlen
(
line
),
line
);
fanout_debug
(
3
,
"line is %d chars: %s
\n
"
,
(
u_int
)
strlen
(
line
),
line
);
...
...
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