summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorlevine <levine@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>1997-12-24 04:19:25 +0000
committerlevine <levine@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>1997-12-24 04:19:25 +0000
commit9593505a42f356b9aa3ebd65a5ccfa33910fd0fd (patch)
treefae80e64b524e846971509af8fed5f7ffa44c18e /examples
parent6782a4a773fe57d228654bc2c70ae0bf6f86d0e0 (diff)
downloadATCD-9593505a42f356b9aa3ebd65a5ccfa33910fd0fd.tar.gz
(main): declare local "i" outside the for loop because it is used after the loop
Diffstat (limited to 'examples')
-rw-r--r--examples/IPC_SAP/SOCK_SAP/CPP-inserver-poll.cpp89
1 files changed, 45 insertions, 44 deletions
diff --git a/examples/IPC_SAP/SOCK_SAP/CPP-inserver-poll.cpp b/examples/IPC_SAP/SOCK_SAP/CPP-inserver-poll.cpp
index 2bad13ea9bd..92798c3d46a 100644
--- a/examples/IPC_SAP/SOCK_SAP/CPP-inserver-poll.cpp
+++ b/examples/IPC_SAP/SOCK_SAP/CPP-inserver-poll.cpp
@@ -4,9 +4,9 @@
// socket wrappers with the SVR4 poll() system call to create a
// single-threaded concurrent server.
-#include "ace/SOCK_Acceptor.h"
+#include "ace/SOCK_Acceptor.h"
#include "ace/SOCK_Stream.h"
-#include "ace/INET_Addr.h"
+#include "ace/INET_Addr.h"
#if defined (ACE_HAS_POLL)
@@ -22,8 +22,9 @@ main (int, char *[])
ACE_SOCK_Stream new_stream;
ACE_HANDLE s_handle = peer_acceptor.get_handle ();
struct pollfd poll_array[MAX_FDS];
+ int i;
- for (int i = 0; i < MAX_FDS; i++)
+ for (i = 0; i < MAX_FDS; i++)
{
poll_array[i].fd = ACE_INVALID_HANDLE;
poll_array[i].events = POLLIN;
@@ -31,7 +32,7 @@ main (int, char *[])
poll_array[0].fd = s_handle;
- for (int n_handles = 1;;)
+ for (int n_handles = 1;;)
{
// Wait for client I/O events (handle interrupts).
while (ACE_OS::poll (poll_array, n_handles) == -1
@@ -42,51 +43,51 @@ main (int, char *[])
// guaranteed to be lowest client descriptor).
for (i = 1; i < n_handles; i++)
- {
- if (poll_array[i].revents & POLLIN)
- {
- char buf[BUFSIZ];
- int n;
- // recv will not block in this case!
- if ((n = ACE_OS::recv (poll_array[i].fd, buf, sizeof buf, 0)) == -1)
- ACE_OS::perror ("read failed");
- else if (n == 0)
- {
- // Handle client connection shutdown.
- if (ACE_OS::close (poll_array[i].fd) == -1)
- ACE_OS::perror ("close");
- poll_array[i].fd = poll_array[--n_handles].fd;
+ {
+ if (poll_array[i].revents & POLLIN)
+ {
+ char buf[BUFSIZ];
+ int n;
+ // recv will not block in this case!
+ if ((n = ACE_OS::recv (poll_array[i].fd, buf, sizeof buf, 0)) == -1)
+ ACE_OS::perror ("read failed");
+ else if (n == 0)
+ {
+ // Handle client connection shutdown.
+ if (ACE_OS::close (poll_array[i].fd) == -1)
+ ACE_OS::perror ("close");
+ poll_array[i].fd = poll_array[--n_handles].fd;
- // Send handshake back to client to unblock it.
- if (ACE_OS::send (poll_array[i].fd, "", 1) != 1)
- ACE_ERROR ((LM_ERROR, "%p\n", "send_n"));
- }
- else
- ACE_OS::printf ("%*s", n, buf), fflush (stdout);
- }
- ACE_OS::fflush (stdout);
- }
+ // Send handshake back to client to unblock it.
+ if (ACE_OS::send (poll_array[i].fd, "", 1) != 1)
+ ACE_ERROR ((LM_ERROR, "%p\n", "send_n"));
+ }
+ else
+ ACE_OS::printf ("%*s", n, buf), fflush (stdout);
+ }
+ ACE_OS::fflush (stdout);
+ }
if (poll_array[0].revents & POLLIN)
- {
- ACE_INET_Addr client;
- ACE_Time_Value nonblock (0, 0);
+ {
+ ACE_INET_Addr client;
+ ACE_Time_Value nonblock (0, 0);
- // Handle all pending connection requests (note use of
- // "polling" feature that doesn't block).
+ // Handle all pending connection requests (note use of
+ // "polling" feature that doesn't block).
- while (ACE_OS::poll (poll_array, 1, nonblock) > 0)
- if (peer_acceptor.accept (new_stream, &client) == -1)
- ACE_OS::perror ("accept");
- else
- {
- const char *s = client.get_host_name ();
+ while (ACE_OS::poll (poll_array, 1, nonblock) > 0)
+ if (peer_acceptor.accept (new_stream, &client) == -1)
+ ACE_OS::perror ("accept");
+ else
+ {
+ const char *s = client.get_host_name ();
- ACE_ASSERT (s != 0);
- ACE_OS::printf ("client %s\n", s);
- ACE_OS::fflush (stdout);
- poll_array[n_handles++].fd = new_stream.get_handle ();
- }
- }
+ ACE_ASSERT (s != 0);
+ ACE_OS::printf ("client %s\n", s);
+ ACE_OS::fflush (stdout);
+ poll_array[n_handles++].fd = new_stream.get_handle ();
+ }
+ }
}
/* NOTREACHED */
return 0;