[ftpii] r280 committed - Incorporate modified version of patch from issue #62 to reinitialise t...

1 view
Skip to first unread message

codesite...@google.com

unread,
Dec 20, 2009, 9:48:34 AM12/20/09
to ftpii-...@googlegroups.com
Revision: 280
Author: joe.g...@psychlaw.com.au
Date: Sun Dec 20 06:47:41 2009
Log: Incorporate modified version of patch from issue #62 to reinitialise
the network after failure

http://code.google.com/p/ftpii/source/detail?r=280

Modified:
/branches/0.0.20/source/ftp.c
/branches/0.0.20/source/ftp.h
/branches/0.0.20/source/ftpii.c
/branches/0.0.20/source/net.c

=======================================
--- /branches/0.0.20/source/ftp.c Wed Dec 9 07:39:31 2009
+++ /branches/0.0.20/source/ftp.c Sun Dec 20 06:47:41 2009
@@ -696,14 +696,14 @@
}
}

-static void process_accept_events(s32 server) {
+static bool process_accept_events(s32 server) {
s32 peer;
struct sockaddr_in client_address;
socklen_t addrlen = sizeof(client_address);
while ((peer = net_accept(server, (struct sockaddr *)&client_address,
&addrlen)) != -EAGAIN) {
if (peer < 0) {
- net_close(server);
- die("Error accepting connection", -peer);
+ printf("Error accepting connection: [%i] %s\n", -peer,
strerror(-peer));
+ return false;
}

printf("Accepted connection from %s!\n",
inet_ntoa(client_address.sin_addr));
@@ -711,14 +711,14 @@
if (num_clients == MAX_CLIENTS) {
printf("Maximum of %u clients reached, not accepting
client.\n", MAX_CLIENTS);
net_close(peer);
- return;
+ return true;
}

client_t *client = malloc(sizeof(client_t));
if (!client) {
printf("Could not allocate memory for client state, not
accepting client.\n");
net_close(peer);
- return;
+ return true;
}
client->socket = peer;
client->representation_type = 'A';
@@ -750,6 +750,7 @@
num_clients++;
}
}
+ return true;
}

static void process_data_events(client_t *client) {
@@ -854,8 +855,8 @@
cleanup_client(client);
}

-void process_ftp_events(s32 server) {
- process_accept_events(server);
+bool process_ftp_events(s32 server) {
+ bool network_down = !process_accept_events(server);
int client_index;
for (client_index = 0; client_index < MAX_CLIENTS; client_index++) {
client_t *client = clients[client_index];
@@ -867,4 +868,5 @@
}
}
}
-}
+ return network_down;
+}
=======================================
--- /branches/0.0.20/source/ftp.h Sat Aug 16 00:01:04 2008
+++ /branches/0.0.20/source/ftp.h Sun Dec 20 06:47:41 2009
@@ -28,7 +28,7 @@

void accept_ftp_client(s32 server);
void set_ftp_password(char *new_password);
-void process_ftp_events(s32 server);
+bool process_ftp_events(s32 server);
void cleanup_ftp();

#endif /* _FTP_H_ */
=======================================
--- /branches/0.0.20/source/ftpii.c Sat Dec 19 02:08:31 2009
+++ /branches/0.0.20/source/ftpii.c Sun Dec 20 06:47:41 2009
@@ -115,11 +115,19 @@
set_password_from_executable(argv[0]);
}

- s32 server = create_server(PORT);
- printf("Listening on TCP port %u...\n", PORT);
+ bool network_down = true;
+ s32 server = -1;
while (!reset()) {
+ if (network_down) {
+ net_close(server);
+ initialise_network();
+ server = create_server(PORT);
+ if (server < 0) continue;
+ printf("Listening on TCP port %u...\n", PORT);
+ network_down = false;
+ }
check_dvd_mount();
- process_ftp_events(server);
+ network_down = process_ftp_events(server);
process_wiimote_events();
process_gamecube_events();
process_timer_events();
=======================================
--- /branches/0.0.20/source/net.c Wed Dec 9 05:19:43 2009
+++ /branches/0.0.20/source/net.c Sun Dec 20 06:47:41 2009
@@ -41,6 +41,7 @@
printf("Waiting for network to initialise...\n");
s32 result = -1;
while (!check_reset_synchronous() && result < 0) {
+ net_deinit();
while (!check_reset_synchronous() && (result = net_init()) ==
-EAGAIN);
if (result < 0) printf("net_init() failed: [%i] %s,
retrying...\n", result, strerror(-result));
}
@@ -84,11 +85,13 @@
s32 ret;
if ((ret = net_bind(server, (struct sockaddr *)&bindAddress,
sizeof(bindAddress))) < 0) {
net_close(server);
- die("Error binding socket", -ret);
+ printf("Error binding socket: [%i] %s\n", -ret, strerror(-ret));
+ return ret;
}
if ((ret = net_listen(server, 3)) < 0) {
net_close(server);
- die("Error listening on socket", -ret);
+ printf("Error listening on socket: [%i] %s\n", -ret,
strerror(-ret));
+ return ret;
}

return server;

Reply all
Reply to author
Forward
0 new messages