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
1d437035
Commit
1d437035
authored
13 years ago
by
Travis Glenn Hansen
Browse files
Options
Downloads
Patches
Plain Diff
formatting and error handling
parent
4fa8c39d
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
+40
-22
40 additions, 22 deletions
fanout.c
with
40 additions
and
22 deletions
fanout.c
+
40
−
22
View file @
1d437035
...
@@ -84,7 +84,7 @@ void unsubscribe (struct client *c, const char *channel_name);
...
@@ -84,7 +84,7 @@ void unsubscribe (struct client *c, const char *channel_name);
// GLOBAL VARS
// GLOBAL VARS
fd_set
readset
,
tempset
;
fd_set
readset
,
tempset
;
u_int
max
;
u_int
max
;
u_
int
client_limit
;
int
client_limit
=
-
1
;
long
server_start_time
;
long
server_start_time
;
//announcement stats
//announcement stats
...
@@ -135,7 +135,7 @@ int main (int argc, char *argv[])
...
@@ -135,7 +135,7 @@ int main (int argc, char *argv[])
socklen_t
clilen
;
socklen_t
clilen
;
struct
sockaddr_in
serv_addr
,
cli_addr
;
struct
sockaddr_in
serv_addr
,
cli_addr
;
struct
rlimit
i_rlimit
,
s_rlimit
;
struct
rlimit
s_rlimit
;
static
struct
option
long_options
[]
=
{
static
struct
option
long_options
[]
=
{
{
"port"
,
1
,
0
,
0
},
{
"port"
,
1
,
0
,
0
},
...
@@ -144,6 +144,7 @@ int main (int argc, char *argv[])
...
@@ -144,6 +144,7 @@ int main (int argc, char *argv[])
{
"pidfile"
,
1
,
0
,
0
},
{
"pidfile"
,
1
,
0
,
0
},
{
"debug-level"
,
1
,
0
,
0
},
{
"debug-level"
,
1
,
0
,
0
},
{
"help"
,
0
,
0
,
0
},
{
"help"
,
0
,
0
,
0
},
{
"client-limit"
,
1
,
0
,
0
},
{
NULL
,
0
,
NULL
,
0
}
{
NULL
,
0
,
NULL
,
0
}
};
};
...
@@ -174,13 +175,23 @@ int main (int argc, char *argv[])
...
@@ -174,13 +175,23 @@ int main (int argc, char *argv[])
case
4
:
case
4
:
debug_level
=
atoi
(
optarg
);
debug_level
=
atoi
(
optarg
);
break
;
break
;
//help
case
5
:
case
5
:
printf
(
"Usage: fanout [options...]
\n
"
);
printf
(
"Usage: fanout [options...]
\n
"
);
printf
(
"pubsub style fanout server
\n\n
"
);
printf
(
"pubsub style fanout server
\n\n
"
);
printf
(
"Recognized options are:
\n
"
);
printf
(
"Recognized options are:
\n
"
);
printf
(
" --port=PORT port to run the service\
printf
(
" --port=PORT port to run the service\
on
\n
"
);
on
\n
"
);
printf
(
" 1986 (default)
\n
"
);
printf
(
" --daemon fork to background
\n
"
);
printf
(
" --daemon fork to background
\n
"
);
printf
(
" --client-limit=LIMIT max connections
\n
"
);
printf
(
" BEWARE ulimit \
restrictions
\n
"
);
printf
(
" you may adjust it using\
ulimit -n X
\n
"
);
printf
(
" or sysctl -w \
fs.file-max=100000
\n
"
);
printf
(
" --logfile=PATH path to log file
\n
"
);
printf
(
" --logfile=PATH path to log file
\n
"
);
printf
(
" --pidfile=PATH path to pid file
\n
"
);
printf
(
" --pidfile=PATH path to pid file
\n
"
);
printf
(
" --debug-level=LEVEL verbosity level
\n
"
);
printf
(
" --debug-level=LEVEL verbosity level
\n
"
);
...
@@ -192,6 +203,16 @@ int main (int argc, char *argv[])
...
@@ -192,6 +203,16 @@ int main (int argc, char *argv[])
\n
"
);
\n
"
);
exit
(
EXIT_SUCCESS
);
exit
(
EXIT_SUCCESS
);
break
;
break
;
//client-limit
case
6
:
client_limit
=
atoi
(
optarg
);
if
(
client_limit
<
1
)
{
printf
(
"invalid client limit: %d
\n
"
,
client_limit
);
exit
(
EXIT_FAILURE
);
}
break
;
}
}
break
;
break
;
default:
default:
...
@@ -278,22 +299,17 @@ int main (int argc, char *argv[])
...
@@ -278,22 +299,17 @@ int main (int argc, char *argv[])
getrlimit
(
RLIMIT_NOFILE
,
&
s_rlimit
);
getrlimit
(
RLIMIT_NOFILE
,
&
s_rlimit
);
/*
/*
//for testing purposes only
struct rlimti i_rlimit;
i_rlimit.rlim_cur = 4; //rlim_cur is larger than rlim_max .EINVAL error
i_rlimit.rlim_cur = 4; //rlim_cur is larger than rlim_max .EINVAL error
i_rlimit.rlim_max = 512;
i_rlimit.rlim_max = 512;
if(setrlimit (RLIMIT_NOFILE,&i_rlimit) == -1)
if(setrlimit (RLIMIT_NOFILE,&i_rlimit) == -1)
fanout_error ("ERROR setting rlimit");
fanout_error ("ERROR setting rlimit");
*/
*/
client_limit
=
s_rlimit
.
rlim_max
;
fanout_debug
(
1
,
"rlimit set at: Soft=%d Hard=%d
\n
"
,
s_rlimit
.
rlim_cur
,
s_rlimit
.
rlim_max
);
if
(
!
daemonize
)
{
client_limit
-=
3
;
}
if
(
logfile
!=
NULL
)
{
client_limit
--
;
}
fanout_debug
(
2
,
"max client connections: %d
\n
"
,
client_limit
);
fanout_debug
(
2
,
"max client connections: %d
\n
"
,
client_limit
);
while
(
1
)
{
while
(
1
)
{
...
@@ -304,7 +320,8 @@ int main (int argc, char *argv[])
...
@@ -304,7 +320,8 @@ int main (int argc, char *argv[])
res
=
select
(
max
+
1
,
&
tempset
,
NULL
,
NULL
,
NULL
);
res
=
select
(
max
+
1
,
&
tempset
,
NULL
,
NULL
,
NULL
);
if
(
res
<
0
)
{
if
(
res
<
0
)
{
fanout_debug
(
1
,
"something bad happened
\n
"
);
fanout_debug
(
0
,
"select failed %s
\n
"
,
strerror
(
errno
));
fanout_error
(
"res was < 0"
);
continue
;
continue
;
}
}
...
@@ -324,10 +341,11 @@ int main (int argc, char *argv[])
...
@@ -324,10 +341,11 @@ int main (int argc, char *argv[])
if
((
client_i
->
fd
=
accept
(
srvsock
,
(
struct
sockaddr
*
)
&
cli_addr
,
if
((
client_i
->
fd
=
accept
(
srvsock
,
(
struct
sockaddr
*
)
&
cli_addr
,
&
clilen
))
==
-
1
)
{
&
clilen
))
==
-
1
)
{
fanout_debug
(
0
,
"%s
\n
"
,
strerror
(
errno
));
fanout_debug
(
0
,
"%s
\n
"
,
strerror
(
errno
));
fanout_error
(
"failed on accept ()"
);
continue
;
continue
;
}
}
if
(
client_count
()
>=
client_limit
)
{
if
(
client_limit
&&
client_count
()
>=
client_limit
)
{
fanout_debug
(
1
,
"hit connection limit of: %d
\n
"
,
client_limit
);
fanout_debug
(
1
,
"hit connection limit of: %d
\n
"
,
client_limit
);
send
(
client_i
->
fd
,
"too many connections
\n
"
,
send
(
client_i
->
fd
,
"too many connections
\n
"
,
strlen
(
"too many connections
\n
"
),
0
);
strlen
(
"too many connections
\n
"
),
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