-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge PR #97: Add UNIX socket support for GDBProtocol and protocol users
This PR adds support for using UNIX sockets for GDB connections instead of TCP. One aspect I didn't consider was where the sockets should be created by default since I use is not None to detect if UNIX should be used. Maybe sockets should be automatically placed in the avatar2 output directory (which should be unique per instance), but this would require more invasive changes to the KWArgs for transport selection. Co-authored-by: Grant Hernandez <[email protected]> Co-authored-by: sampl <[email protected]>
- Loading branch information
Showing
6 changed files
with
157 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import socket | ||
import threading | ||
import os | ||
import time | ||
|
||
# oneshot UNIX to TCP socket proxy. Stops after first connection | ||
def unix2tcp(unix_socket_path, tcp_host, tcp_port): | ||
try: | ||
os.unlink(unix_socket_path) | ||
except OSError: | ||
pass | ||
|
||
usock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) | ||
tsock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | ||
|
||
usock.bind(unix_socket_path) | ||
usock.listen(1) | ||
|
||
def proxy_loop(): | ||
uconn, addr = usock.accept() | ||
tsock.connect((tcp_host, tcp_port)) | ||
|
||
uconn.setblocking(False) | ||
tsock.setblocking(False) | ||
|
||
while True: | ||
data = None | ||
|
||
try: | ||
data = uconn.recv(1000) | ||
if len(data) == 0: | ||
break | ||
tsock.sendall(data) | ||
except BlockingIOError: | ||
pass | ||
|
||
try: | ||
data = tsock.recv(1000) | ||
if len(data) == 0: | ||
break | ||
uconn.sendall(data) | ||
except BlockingIOError: | ||
pass | ||
|
||
usock.close() | ||
uconn.close() | ||
tsock.close() | ||
|
||
threading.Thread(target=proxy_loop, daemon=True).start() | ||
|