Revision: 76679
http://sourceforge.net/p/brlcad/code/76679
Author: starseeker
Date: 2020-08-07 13:45:31 +0000 (Fri, 07 Aug 2020)
Log Message:
-----------
Move a few functions and rename to make it a little easier to compare the MGED
version of this code with the standalone version.
Modified Paths:
--------------
brlcad/trunk/src/fbserv/fbserv.c
Modified: brlcad/trunk/src/fbserv/fbserv.c
===================================================================
--- brlcad/trunk/src/fbserv/fbserv.c 2020-08-06 18:38:32 UTC (rev 76678)
+++ brlcad/trunk/src/fbserv/fbserv.c 2020-08-07 13:45:31 UTC (rev 76679)
@@ -77,9 +77,11 @@
#include "bio.h"
#include "bu/app.h"
+#include "bu/color.h"
+#include "bu/exit.h"
+#include "bu/getopt.h"
+#include "bu/log.h"
#include "bu/malloc.h"
-#include "bu/getopt.h"
-#include "bu/exit.h"
#include "bu/snooze.h"
#include "vmath.h"
#include "dm.h"
@@ -194,13 +196,36 @@
return 0;
}
+/*
+ * Communication error. An error occurred on the PKG link.
+ * It may be local, or it may be between us and the client we are serving.
+ * We send a copy to syslog or stderr.
+ * Don't send one down the wire, this can cause loops.
+ */
+static void
+communications_error(const char *str)
+{
+#if defined(HAVE_SYSLOG_H)
+ if (use_syslog) {
+ syslog(LOG_ERR, "%s", str);
+ } else {
+ fprintf(stderr, "%s", str);
+ }
+#else
+ fprintf(stderr, "%s", str);
+#endif
+ if (verbose) {
+ fprintf(stderr, "%s", str);
+ }
+}
+
static void
-setup_socket(int fd)
+fbserv_setup_socket(int fd)
{
int on = 1;
-#ifdef SO_KEEPALIVE
+#if defined(SO_KEEPALIVE)
if (setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, (char *)&on, sizeof(on)) < 0)
{
# ifdef HAVE_SYSLOG_H
syslog(LOG_WARNING, "setsockopt (SO_KEEPALIVE): %s", strerror(errno));
@@ -207,11 +232,10 @@
# endif
}
#endif
-#ifdef SO_RCVBUF
+#if defined(SO_RCVBUF)
/* try to set our buffers up larger */
{
- int m = 0;
- int n = 0;
+ int m = -1, n = -1;
int val;
int size;
@@ -224,14 +248,30 @@
(char *)&val, sizeof(val));
if (m >= 0 && n >= 0) break;
}
- if (m < 0 || n < 0) perror("fbserv setsockopt()");
+
+ if (m < 0 || n < 0)
+ perror("setsockopt");
}
#endif
}
+static void
+fbserv_drop_client(int sub)
+{
+ int fd;
-void
-new_client(struct pkg_conn *pcp)
+ if (clients[sub] == PKC_NULL)
+ return;
+
+ fd = clients[sub]->pkc_fd;
+
+ FD_CLR(fd, &select_list);
+ pkg_close(clients[sub]);
+ clients[sub] = PKC_NULL;
+}
+
+static void
+fbserv_new_client(struct pkg_conn *pcp)
{
int i;
@@ -244,7 +284,7 @@
clients[i] = pcp;
FD_SET(pcp->pkc_fd, &select_list);
V_MAX(max_fd, pcp->pkc_fd);
- setup_socket(pcp->pkc_fd);
+ fbserv_setup_socket(pcp->pkc_fd);
return;
}
fprintf(stderr, "fbserv: too many clients\n");
@@ -252,47 +292,8 @@
}
-void
-drop_client(int sub)
-{
- int fd;
- if (clients[sub] == PKC_NULL)
- return;
-
- fd = clients[sub]->pkc_fd;
-
- FD_CLR(fd, &select_list);
- pkg_close(clients[sub]);
- clients[sub] = PKC_NULL;
-}
-
-
/*
- * Communication error. An error occurred on the PKG link.
- * It may be local, or it may be between us and the client we are serving.
- * We send a copy to syslog or stderr.
- * Don't send one down the wire, this can cause loops.
- */
-static void
-comm_error(const char *str)
-{
-#if defined(HAVE_SYSLOG_H)
- if (use_syslog) {
- syslog(LOG_ERR, "%s", str);
- } else {
- fprintf(stderr, "%s", str);
- }
-#else
- fprintf(stderr, "%s", str);
-#endif
- if (verbose) {
- fprintf(stderr, "%s", str);
- }
-}
-
-
-/*
* Loop forever handling clients as they come and go.
* Access to the framebuffer may be interleaved, if the user
* wants it that way.
@@ -336,7 +337,7 @@
/* Accept any new client connections */
if (netfd > 0 && FD_ISSET(netfd, &infds)) {
- new_client(pkg_getclient(netfd, fb_server_pkg_switch, comm_error,
0));
+ fbserv_new_client(pkg_getclient(netfd, fb_server_pkg_switch,
communications_error, 0));
nopens++;
}
@@ -350,7 +351,7 @@
if (! FD_ISSET(clients[i]->pkc_fd, &infds)) continue;
if (pkg_suckin(clients[i]) <= 0) {
/* Probably EOF */
- drop_client(i);
+ fbserv_drop_client(i);
ncloses++;
continue;
}
@@ -415,7 +416,7 @@
netfd = 0;
if (is_socket(netfd)) {
init_syslog();
- new_client(pkg_transerver(fb_server_pkg_switch, comm_error));
+ fbserv_new_client(pkg_transerver(fb_server_pkg_switch,
communications_error));
max_fd = 8;
once_only = 1;
main_loop();
@@ -448,7 +449,7 @@
/*
* Hang an unending listen for PKG connections
*/
- if ((netfd = pkg_permserver(portname, 0, 0, comm_error)) < 0)
+ if ((netfd = pkg_permserver(portname, 0, 0, communications_error)) < 0)
bu_exit(-1, NULL);
FD_SET(netfd, &select_list);
V_MAX(max_fd, netfd);
@@ -471,13 +472,13 @@
}
init_syslog();
- while ((netfd = pkg_permserver(portname, 0, 0, comm_error)) < 0) {
+ while ((netfd = pkg_permserver(portname, 0, 0, communications_error)) < 0)
{
static int error_count=0;
bu_snooze(BU_SEC2USEC(1));
if (error_count++ < 60) {
continue;
}
- comm_error("Unable to start the stand-alone framebuffer daemon after 60
seconds, giving up.");
+ communications_error("Unable to start the stand-alone framebuffer
daemon after 60 seconds, giving up.");
return 1;
}
@@ -485,7 +486,7 @@
int fbstat;
struct pkg_conn *pcp;
- pcp = pkg_getclient(netfd, fb_server_pkg_switch, comm_error, 0);
+ pcp = pkg_getclient(netfd, fb_server_pkg_switch, communications_error,
0);
if (pcp == PKC_ERROR)
break; /* continue is unlikely to work */
@@ -496,7 +497,7 @@
/* Create 2nd level child process, "double detach" */
if (fork() == 0) {
/* 2nd level child -- start work! */
- new_client(pcp);
+ fbserv_new_client(pcp);
once_only = 1;
main_loop();
return 0;
@@ -516,7 +517,6 @@
return 2;
}
-
#ifndef _WIN32
/*
* Handles error or log messages from the frame buffer library.
@@ -546,8 +546,8 @@
for (i = MAX_CLIENTS-1; i >= 0; i--) {
if (clients[i] == NULL) continue;
if (pkg_send(MSG_ERROR, outbuf, want, clients[i]) != want) {
- comm_error("pkg_send error in fb_log, message was:\n");
- comm_error(outbuf);
+ communications_error("pkg_send error in fb_log, message was:\n");
+ communications_error(outbuf);
} else {
nsent++;
}
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits