示例#1
0
    def _handle_stage_connecting(self, data):
        if self._is_local:
            data = self._encryptor.encrypt(data)
        self._data_to_write_to_remote.append(data)
        if self._is_local and not self._fastopen_connected and \
                self._config['fast_open']:
            # for sslocal and fastopen, we basically wait for data and use
            # sendto to connect
            try:
                # only connect once
                self._fastopen_connected = True
                remote_sock = \
                    self._create_remote_socket(self._chosen_server[0],
                                               self._chosen_server[1])
                self._loop.add(remote_sock, eventloop.POLL_ERR, self._server)
                data = b''.join(self._data_to_write_to_remote)
                l = len(data)
                fastopen.connect(remote_sock.fileno(), self._chosen_server[0], str(self._chosen_server[1]))
                s = remote_sock.send(data)

                if s < l:
                    data = data[s:]
                    self._data_to_write_to_remote = [data]
                else:
                    self._data_to_write_to_remote = []
                self._update_stream(STREAM_UP, WAIT_STATUS_READWRITING)
            except (OSError, IOError) as e:
                if eventloop.errno_from_exception(e) == errno.EINPROGRESS:
                    # in this case data is not sent at all
                    self._update_stream(STREAM_UP, WAIT_STATUS_READWRITING)
                elif eventloop.errno_from_exception(e) == errno.ENOTCONN:
                    logging.error('fast open not supported on this OS')
                    self._config['fast_open'] = False
                    self.destroy()
                else:
                    shell.print_exception(e)
                    if self._config['verbose']:
                        traceback.print_exc()
                    self.destroy()
示例#2
0
文件: client.py 项目: crvv/fastopen
#!/usr/bin/env python3

# Echo client program
import socket
import fastopen

MSG_FASTOPEN = 0x20000000

HOST = 'localhost'  # The remote host
PORT = 50007  # The same port as used by the server
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

fastopen.connect(s.fileno(), HOST, PORT)

s.send(b'Hello, world')

data = s.recv(1024)
s.close()
print('Received', repr(data))
示例#3
0
#!/usr/bin/env python3

# Echo client program
import socket
import fastopen

MSG_FASTOPEN = 0x20000000

HOST = 'localhost'    # The remote host
PORT = 50007              # The same port as used by the server
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

fastopen.connect(s.fileno(), HOST, PORT)

s.send(b'Hello, world')

data = s.recv(1024)
s.close()
print('Received', repr(data))