-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
clean up copies of file descriptor and remove copyinit
- Loading branch information
1 parent
99b32d2
commit 42c005b
Showing
6 changed files
with
86 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
from .tcp import TCPAddr, TCPConnection, resolve_internet_addr | ||
from .socket import Socket | ||
|
||
|
||
@value | ||
struct Dialer(): | ||
var local_address: TCPAddr | ||
|
||
fn dial(self, network: String, address: String) raises -> TCPConnection: | ||
var tcp_addr = resolve_internet_addr(network, address) | ||
var socket = Socket(local_address=self.local_address) | ||
socket.connect(tcp_addr.ip, tcp_addr.port) | ||
print(String("Connected to ") + socket.remote_address) | ||
return TCPConnection(socket ^) | ||
|
||
|
||
fn dial_tcp(network: String, local_address: TCPAddr) raises -> TCPConnection: | ||
# TODO: Add conversion of domain name to ip address | ||
return Dialer(local_address).dial( | ||
network, local_address.ip + ":" + str(local_address.port) | ||
) | ||
|
||
|
||
fn dial_tcp(network: String, ip: String, port: Int) raises -> TCPConnection: | ||
return Dialer(TCPAddr(ip, port)).dial(network, ip + ":" + str(port)) |
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