components/python/python26/patches/Python26-23-none-on-connect.patch
author Kevin Crowe <Kevin.Crowe@oracle.com>
Fri, 12 Aug 2011 12:26:15 -0700
changeset 470 fda4329d05f4
child 841 1a62cefa636d
permissions -rw-r--r--
7016862 Problem with utility/python
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
470
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
     1
--- Python-2.6.4/Lib/smtpd.py	Thu Aug  4 09:36:51 2011
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
     2
+++ Python-2.6.4/Lib/new.smtpd.py	Thu Aug  4 09:51:49 2011
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
     3
@@ -121,7 +121,15 @@
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
     4
         self.__rcpttos = []
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
     5
         self.__data = ''
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
     6
         self.__fqdn = socket.getfqdn()
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
     7
-        self.__peer = conn.getpeername()
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
     8
+        try:
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
     9
+            self.__peer = conn.getpeername()
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    10
+        except socket.error as err:
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    11
+            # a race condition  may occur if the other end is closing
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    12
+            # before we can get the peername
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    13
+            self.close()
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    14
+            if err.args[0] != errno.ENOTCONN:
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    15
+                raise
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    16
+            return
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    17
         print >> DEBUGSTREAM, 'Peer:', repr(self.__peer)
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    18
         self.push('220 %s %s' % (self.__fqdn, __version__))
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    19
         self.set_terminator('\r\n')
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    20
@@ -285,9 +293,11 @@
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    21
             localaddr, remoteaddr)
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    22
 
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    23
     def handle_accept(self):
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    24
-        conn, addr = self.accept()
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    25
-        print >> DEBUGSTREAM, 'Incoming connection from %s' % repr(addr)
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    26
-        channel = SMTPChannel(self, conn, addr)
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    27
+        pair = self.accept()
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    28
+        if pair is not None:
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    29
+            conn, addr = pair
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    30
+            print >> DEBUGSTREAM, 'Incoming connection from %s' % repr(addr)
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    31
+            channel = SMTPChannel(self, conn, addr)
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    32
 
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    33
     # API for "doing something useful with the message"
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    34
     def process_message(self, peer, mailfrom, rcpttos, data):
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    35
--- Python-2.6.4/Lib/asyncore.py	Wed Apr 15 16:00:41 2009
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    36
+++ Python-2.6.4/Lib/new.asyncore.py	Thu Aug  4 09:55:22 2011
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    37
@@ -340,12 +340,15 @@
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    38
         # XXX can return either an address pair or None
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    39
         try:
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    40
             conn, addr = self.socket.accept()
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    41
-            return conn, addr
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    42
-        except socket.error, why:
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    43
-            if why.args[0] == EWOULDBLOCK:
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    44
-                pass
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    45
+        except TypeError:
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    46
+            return None
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    47
+        except socket.error as why:
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    48
+            if why.args[0] in (EWOULDBLOCK, ECONNABORTED):
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    49
+                return None
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    50
             else:
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    51
                 raise
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    52
+        else:
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    53
+            return conn, addr
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    54
 
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    55
     def send(self, data):
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    56
         try:
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    57
--- Python-2.6.4/Doc/library/asyncore.rst	Wed Apr 15 16:00:41 2009
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    58
+++ Python-2.6.4/Doc/library/new.asyncore.rst	Thu Aug  4 10:05:40 2011
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    59
@@ -210,10 +210,13 @@
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    60
    .. method:: accept()
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    61
 
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    62
       Accept a connection.  The socket must be bound to an address and listening
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    63
-      for connections.  The return value is a pair ``(conn, address)`` where
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    64
-      *conn* is a *new* socket object usable to send and receive data on the
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    65
-      connection, and *address* is the address bound to the socket on the other
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    66
-      end of the connection.
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    67
+      for connections.  The return value can be either ``None`` or a pair
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    68
+      ``(conn, address)`` where *conn* is a *new* socket object usable to send
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    69
+      and receive data on the connection, and *address* is the address bound to
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    70
+      the socket on the other end of the connection.
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    71
+      When ``None`` is returned it means the connection didn't take place, in
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    72
+      which case the server should just ignore this event and keep listening
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    73
+      for further incoming connections.
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    74
 
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    75
 
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    76
    .. method:: close()
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    77
@@ -223,6 +226,12 @@
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    78
       flushed).  Sockets are automatically closed when they are
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    79
       garbage-collected.
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    80
 
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    81
+.. class:: dispatcher_with_send()
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    82
+
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    83
+   A :class:`dispatcher` subclass which adds simple buffered output capability,
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    84
+   useful for simple clients. For more sophisticated usage use
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    85
+   :class:`asynchat.async_chat`.
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    86
+
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    87
 .. class:: file_dispatcher()
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    88
 
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    89
    A file_dispatcher takes a file descriptor or file object along with an
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    90
@@ -239,7 +248,7 @@
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    91
    socket for use by the :class:`file_dispatcher` class.  Availability: UNIX.
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    92
 
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    93
 
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    94
-.. _asyncore-example:
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    95
+.. _asyncore-example-1:
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    96
 
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    97
 asyncore Example basic HTTP client
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    98
 ----------------------------------
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    99
@@ -249,7 +258,7 @@
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   100
 
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   101
    import asyncore, socket
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   102
 
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   103
-   class http_client(asyncore.dispatcher):
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   104
+   class HTTPClient(asyncore.dispatcher):
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   105
 
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   106
        def __init__(self, host, path):
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   107
            asyncore.dispatcher.__init__(self)
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   108
@@ -273,6 +282,45 @@
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   109
            sent = self.send(self.buffer)
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   110
            self.buffer = self.buffer[sent:]
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   111
 
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   112
-   c = http_client('www.python.org', '/')
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   113
 
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   114
+   client = HTTPClient('www.python.org', '/')
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   115
    asyncore.loop()
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   116
+
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   117
+.. _asyncore-example-2:
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   118
+
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   119
+asyncore Example basic echo server
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   120
+----------------------------------
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   121
+
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   122
+Here is abasic echo server that uses the :class:`dispatcher` class to accept
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   123
+connections and dispatches the incoming connections to a handler::
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   124
+
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   125
+    import asyncore
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   126
+    import socket
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   127
+
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   128
+    class EchoHandler(asyncore.dispatcher_with_send):
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   129
+
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   130
+        def handle_read(self):
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   131
+            data = self.recv(8192)
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   132
+            self.send(data)
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   133
+
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   134
+    class EchoServer(asyncore.dispatcher):
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   135
+
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   136
+        def __init__(self, host, port):
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   137
+            asyncore.dispatcher.__init__(self)
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   138
+            self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   139
+            self.set_reuse_addr()
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   140
+            self.bind((host, port))
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   141
+            self.listen(5)
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   142
+
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   143
+        def handle_accept(self):
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   144
+            pair = self.accept()
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   145
+            if pair is None:
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   146
+                pass
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   147
+            else:
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   148
+                sock, addr = pair
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   149
+                print 'Incoming connection from %s' % repr(addr)
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   150
+                handler = EchoHandler(sock)
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   151
+
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   152
+    server = EchoServer('localhost', 8080)
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   153
+    asyncore.loop()
fda4329d05f4 7016862 Problem with utility/python
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   154
+