aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/ChangeLog10
-rw-r--r--src/hyper/spadint.c6
-rw-r--r--src/include/sockio.h6
-rw-r--r--src/lib/sockio-c.c132
-rw-r--r--src/sman/session.c10
-rw-r--r--src/sman/sman.c25
6 files changed, 79 insertions, 110 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index cecdaa95..c37a272a 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,13 @@
+2013-06-29 Gabriel Dos Reis <gdr@integrable-solutions.net>
+
+ * include/sockio.h (accept_connection): Take no argument.
+ (server): Adjust type.
+ * lib/sockio-c.c: Implement changes.
+ * hyper/spadint.c (accept_menu_server_connection): Adjust use of
+ server.
+ * sman/session.c (manage_sessions): Likewise.
+ * sman/sman.c (manage_spad_io): Likewise.
+
2013-06-28 Gabriel Dos Reis <gdr@integrable-solutions.net>
* gui/conversation.cc (accumulate_paragraphs): Remove.
diff --git a/src/hyper/spadint.c b/src/hyper/spadint.c
index d31ed6da..7699a653 100644
--- a/src/hyper/spadint.c
+++ b/src/hyper/spadint.c
@@ -1,7 +1,7 @@
/*
Copyright (C) 1991-2002, The Numerical Algorithms Group Ltd.
All rights reserved.
- Copyright (C) 2007-2010, Gabriel Dos Reis.
+ Copyright (C) 2007-2013, Gabriel Dos Reis.
All rights reserved.
Redistribution and use in source and binary forms, with or without
@@ -350,8 +350,8 @@ accept_menu_server_connection(HyperDocPage *page)
continue;
}
- if (server[1].socket > 0 && FD_ISSET(server[1].socket, &rd)) {
- sock = accept_menu_connection(server + 1);
+ if (server.socket > 0 && FD_ISSET(server.socket, &rd)) {
+ sock = accept_menu_connection(&server);
if (sock == 0)
return;
if (sock->purpose == InterpWindow) {
diff --git a/src/include/sockio.h b/src/include/sockio.h
index 14b06cd8..f77f8d50 100644
--- a/src/include/sockio.h
+++ b/src/include/sockio.h
@@ -1,7 +1,7 @@
/*
Copyright (C) 1991-2002, The Numerical Algorithms Group Ltd.
All rights reserved.
- Copyright (C) 2007-2010, Gabriel Dos Reis
+ Copyright (C) 2007-2013, Gabriel Dos Reis
All rights reserved.
Redistribution and use in source and binary forms, with or without
@@ -123,7 +123,7 @@ OPENAXIOM_C_EXPORT int make_server_name(char*, const char*);
OPENAXIOM_C_EXPORT int make_server_number();
OPENAXIOM_C_EXPORT openaxiom_sio* connect_to_local_server(const char*, int, int);
OPENAXIOM_C_EXPORT int open_server(const char*);
-OPENAXIOM_C_EXPORT int accept_connection(openaxiom_sio*);
+OPENAXIOM_C_EXPORT int accept_connection();
OPENAXIOM_C_EXPORT int sselect(int, fd_set*, fd_set*, fd_set*, void*);
OPENAXIOM_C_EXPORT void close_socket(openaxiom_socket, const char*);
@@ -205,7 +205,7 @@ OPENAXIOM_C_EXPORT int server_switch();
/* table of dedicated socket types */
OPENAXIOM_C_EXPORT openaxiom_sio *purpose_table[];
-OPENAXIOM_C_EXPORT openaxiom_sio server[];
+OPENAXIOM_C_EXPORT openaxiom_sio server;
OPENAXIOM_C_EXPORT openaxiom_sio clients[];
OPENAXIOM_C_EXPORT fd_set socket_mask;
OPENAXIOM_C_EXPORT fd_set server_mask;
diff --git a/src/lib/sockio-c.c b/src/lib/sockio-c.c
index d44eb818..24b8f475 100644
--- a/src/lib/sockio-c.c
+++ b/src/lib/sockio-c.c
@@ -82,8 +82,8 @@ namespace OpenAxiom {
/* socket description of spad clients */
openaxiom_sio clients[MaxClients];
-/* AF_LOCAL and AF_INET sockets for server */
-openaxiom_sio server[2];
+/* Local socket for server */
+openaxiom_sio server;
/* table of dedicated socket types */
openaxiom_sio *purpose_table[TotalMaxPurposes];
@@ -990,8 +990,8 @@ connect_to_local_server_new(const char *server_name, int purpose, int time_out)
return NULL;
}
- memset(server[1].addr.u_addr.sa_data, 0,
- sizeof(server[1].addr.u_addr.sa_data));
+ memset(server.addr.u_addr.sa_data, 0,
+ sizeof(server.addr.u_addr.sa_data));
sock->addr.u_addr.sa_family = OPENAXIOM_AF_LOCAL;
strcpy(sock->addr.u_addr.sa_data, name);
for(i=0; i<max_con; i++) {
@@ -1044,8 +1044,8 @@ connect_to_local_server(const char *server_name, int purpose, int time_out)
return NULL;
}
/* connect socket using name specified in command line */
- memset(server[1].addr.u_addr.sa_data, 0,
- sizeof(server[1].addr.u_addr.sa_data));
+ memset(server.addr.u_addr.sa_data, 0,
+ sizeof(server.addr.u_addr.sa_data));
sock->addr.u_addr.sa_family = OPENAXIOM_AF_LOCAL;
strcpy(sock->addr.u_addr.sa_data, name);
for(i=0; i<max_con; i++) {
@@ -1086,7 +1086,7 @@ remote_stdio(openaxiom_sio *sock)
FD_ZERO(&rd);
FD_SET(sock->socket,&rd);
FD_SET(0, &rd);
- len = sselect(FD_SETSIZE, (fd_set *)&rd, (fd_set *)0, (fd_set *)0, NULL);
+ len = sselect(FD_SETSIZE, &rd, nullptr, nullptr, NULL);
if (len == -1) {
perror("stdio select");
return;
@@ -1156,16 +1156,15 @@ make_server_name(char *name, const char* base)
static void
init_socks()
{
- int i;
FD_ZERO(&socket_mask);
FD_ZERO(&server_mask);
init_purpose_table();
- for(i=0; i<2; i++) server[i].socket = 0;
- for(i=0; i<MaxClients; i++) clients[i].socket = 0;
+ server.socket = 0;
+ for (int i=0; i<MaxClients; i++)
+ clients[i].socket = 0;
}
-/* client Spad server sockets. Two sockets are created: server[0]
- is the internet server socket, and server[1] is a local domain socket. */
+/* client Spad server sockets: server is a local domain socket. */
OPENAXIOM_C_EXPORT int
open_server(const char* server_name)
{
@@ -1177,52 +1176,26 @@ open_server(const char* server_name)
#endif
if (make_server_name(name, server_name) == -1)
return -2;
- /* create the socket internet socket */
- server[0].socket = 0;
-/* server[0].socket = openaxiom_socket_stream_link(AF_INET);
- if (is_invalid_socket(&server[0])) {
- server[0].socket = 0;
- } else {
- server[0].addr.i_addr.sin_family = AF_INET;
- server[0].addr.i_addr.sin_addr.s_addr = INADDR_ANY;
- server[0].addr.i_addr.sin_port = 0;
- if (bind(server[0].socket, &server[0].addr.i_addr,
- sizeof(server[0].addr.i_addr))) {
- perror("binding INET stream socket");
- server[0].socket = 0;
- return -1;
- }
- length = sizeof(server[0].addr.i_addr);
- if (getsockname(server[0].socket, &server[0].addr.i_addr, &length)) {
- perror("getting INET server socket name");
- server[0].socket = 0;
- return -1;
- }
- server_port = ntohs(server[0].addr.i_addr.sin_port);
- FD_SET(server[0].socket, &socket_mask);
- FD_SET(server[0].socket, &server_mask);
- listen(server[0].socket,5);
- } */
/* Next create the local domain socket */
- server[1].socket = openaxiom_socket_stream_link(OPENAXIOM_AF_LOCAL);
- if (is_invalid_socket(&server[1])) {
+ server.socket = openaxiom_socket_stream_link(OPENAXIOM_AF_LOCAL);
+ if (is_invalid_socket(&server)) {
perror("opening local server socket");
- server[1].socket = 0;
+ server.socket = 0;
return -2;
} else {
- server[1].addr.u_addr.sa_family = OPENAXIOM_AF_LOCAL;
- memset(server[1].addr.u_addr.sa_data, 0,
- sizeof(server[1].addr.u_addr.sa_data));
- strcpy(server[1].addr.u_addr.sa_data, name);
- if (bind(server[1].socket, &server[1].addr.u_addr,
- sizeof(server[1].addr.u_addr))) {
+ server.addr.u_addr.sa_family = OPENAXIOM_AF_LOCAL;
+ memset(server.addr.u_addr.sa_data, 0,
+ sizeof(server.addr.u_addr.sa_data));
+ strcpy(server.addr.u_addr.sa_data, name);
+ if (bind(server.socket, &server.addr.u_addr,
+ sizeof(server.addr.u_addr))) {
perror("binding local server socket");
- server[1].socket = 0;
+ server.socket = 0;
return -2;
}
- FD_SET(server[1].socket, &socket_mask);
- FD_SET(server[1].socket, &server_mask);
- listen(server[1].socket, 5);
+ FD_SET(server.socket, &socket_mask);
+ FD_SET(server.socket, &server_mask);
+ listen(server.socket, 5);
}
s = oa_getenv("SPADSERVER");
if (s == NULL) {
@@ -1232,57 +1205,55 @@ open_server(const char* server_name)
return 0;
}
+/* reads a the socket purpose declaration for classification */
+OPENAXIOM_C_EXPORT void
+get_socket_type(openaxiom_sio *sock)
+{
+ sock->pid = get_int(sock);
+ sock->purpose = get_int(sock);
+ sock->remote = get_int(sock);
+ send_int(sock, oa_getpid());
+ send_int(sock, sock->socket);
+ purpose_table[sock->purpose] = sock;
+}
+
OPENAXIOM_C_EXPORT int
-accept_connection(openaxiom_sio *sock)
+accept_connection()
{
- int client;
- for(client=0; client<MaxClients && clients[client].socket != 0; client++);
+ int client = 0;
+ while (client < MaxClients && clients[client].socket != 0)
+ ++client;
if (client == MaxClients) {
printf("Ran out of client openaxiom_sio structures\n");
return -1;
}
- clients[client].socket = accept(sock->socket, 0, 0);
+ clients[client].socket = accept(server.socket, 0, 0);
if (is_invalid_socket(&clients[client])) {
perror("accept_connection");
clients[client].socket = 0;
return -1;
}
FD_SET(clients[client].socket, &socket_mask);
- get_socket_type(clients+client);
+ get_socket_type(&clients[client]);
return clients[client].purpose;
}
-/* reads a the socket purpose declaration for classification */
-OPENAXIOM_C_EXPORT void
-get_socket_type(openaxiom_sio *sock)
-{
- sock->pid = get_int(sock);
- sock->purpose = get_int(sock);
- sock->remote = get_int(sock);
- send_int(sock, oa_getpid());
- send_int(sock, sock->socket);
- purpose_table[sock->purpose] = sock;
-}
-
OPENAXIOM_C_EXPORT int
sock_accept_connection(int purpose)
{
fd_set rd;
- int ret_val, i, p;
+ int ret_val, p;
if (oa_getenv("SPADNUM") == NULL) return -1;
while (1) {
rd = server_mask;
- ret_val = sselect(FD_SETSIZE, (fd_set *)&rd, (fd_set *)0, (fd_set *)0, NULL);
+ ret_val = sselect(FD_SETSIZE, &rd, nullptr, nullptr, NULL);
if (ret_val == -1) {
perror ("Select");
return -1;
}
- for(i=0; i<2; i++) {
- if (is_valid_socket(&server[i])
- && FD_ISSET(server[i].socket, &rd)) {
- p = accept_connection(server+i);
- if (p == purpose) return 1;
- }
+ if (is_valid_socket(&server) && FD_ISSET(server.socket, &rd)) {
+ p = accept_connection();
+ if (p == purpose) return 1;
}
}
}
@@ -1292,7 +1263,7 @@ sock_accept_connection(int purpose)
OPENAXIOM_C_EXPORT int
server_switch()
{
- int ret_val, i, cmd = 0;
+ int ret_val, cmd = 0;
fd_set rd, wr, ex, fds_mask;
FD_ZERO(&rd);
FD_ZERO(&wr);
@@ -1314,11 +1285,8 @@ server_switch()
/* perror ("Select in switch"); */
return -1;
}
- for(i=0; i<2; i++) {
- if (is_valid_socket(&server[i])
- && (FD_ISSET(server[i].socket, &rd)))
- accept_connection(server+i);
- }
+ if (is_valid_socket(&server) && FD_ISSET(server.socket, &rd))
+ accept_connection();
} while (purpose_table[SessionManager] == NULL);
FD_SET(purpose_table[SessionManager]->socket, &fds_mask);
if (FD_ISSET(purpose_table[SessionManager]->socket, &rd)) {
diff --git a/src/sman/session.c b/src/sman/session.c
index 431580d8..6c3746d2 100644
--- a/src/sman/session.c
+++ b/src/sman/session.c
@@ -2,7 +2,7 @@
Copyright (c) 1991-2002, The Numerical Algorithms Group Ltd.
All rights reserved.
- Copyright (C) 2007-2009, Gabriel Dos Reis.
+ Copyright (C) 2007-2013, Gabriel Dos Reis.
All rights reserved.
Redistribution and use in source and binary forms, with or without
@@ -445,9 +445,9 @@ fprintf(stderr,"rd=%u]\n",*((long *)rd.fds_bits));
read_from_spad_io(); }
- if (FD_ISSET(server[1].socket, &rd)) {
+ if (FD_ISSET(server.socket, &rd)) {
/* Someone wants to connect to our server socket */
- accept_session_connection(server+1); }
+ accept_session_connection(&server); }
for(pSock=plSock; pSock != (Sock_List *) 0 ; pSock=pSock->next) {
@@ -521,9 +521,9 @@ main(void)
else {
#ifdef DEBUG
fprintf(stderr, "session: opened SessionServer , fd = %d\n",
- server[1].socket);
+ server.socket);
#endif
- FD_SET(server[1].socket,&session_socket_mask);
+ FD_SET(server.socket,&session_socket_mask);
}
manage_sessions();
return(0);
diff --git a/src/sman/sman.c b/src/sman/sman.c
index 1efe4c5c..c8c357f2 100644
--- a/src/sman/sman.c
+++ b/src/sman/sman.c
@@ -1,7 +1,7 @@
/*
Copyright (c) 1991-2002, The Numerical Algorithms Group Ltd.
All rights reserved.
- Copyright (C) 2007-2010, Gabriel Dos Reis.
+ Copyright (C) 2007-2013, Gabriel Dos Reis.
All rights reserved.
Redistribution and use in source and binary forms, with or without
@@ -84,7 +84,6 @@ static void clean_hypertex_socket(void);
static void read_from_spad_io(int);
static void read_from_manager(int);
static void manage_spad_io(int);
-static void init_spad_process_list(void);
static SpadProcess* find_child(int);
static void kill_all_children(void);
static void clean_up_terminal(void);
@@ -655,20 +654,18 @@ manage_spad_io(int ptcNum)
if (FD_ISSET(ptcNum, &rd)) {
read_from_spad_io(ptcNum);
}
- for(i=0; i<2; i++) {
- if (server[i].socket > 0 && FD_ISSET(server[i].socket, &rd)) {
- p = accept_connection(server+i);
- switch(p) {
- case SessionIO:
+ if (server.socket > 0 && FD_ISSET(server.socket, &rd)) {
+ p = accept_connection();
+ switch(p) {
+ case SessionIO:
session_io = purpose_table[SessionIO];
/* printf("connected session manager\n\r");*/
printf("\n");
break;
- default:
+ default:
printf("sman: Unknown connection request type: %d\n", p);
break;
- }
- }
+ }
}
if (session_io != NULL && FD_ISSET(session_io->socket, &rd)) {
read_from_manager(ptcNum);
@@ -676,12 +673,6 @@ manage_spad_io(int ptcNum)
}
}
-static void
-init_spad_process_list(void)
-{
- spad_process_list = NULL;
-}
-
#if 0
static void
print_spad_process_list()
@@ -780,7 +771,7 @@ main(int argc, char *argv[])
setlocale(LC_ALL, "");
bsdSignal(SIGINT, SIG_IGN,RestartSystemCalls);
init_term_io();
- init_spad_process_list();
+ spad_process_list = NULL;
start_the_Axiom(&command);
if (open_server(SessionIOName) == -2) {
fprintf(stderr, "Fatal error opening I/O socket\n");