This commit is contained in:
a 2023-06-26 03:22:29 -05:00
parent b0b26fc15a
commit 985ffb1f13
No known key found for this signature in database
GPG Key ID: 374BC539FE795AF0
3 changed files with 16 additions and 22 deletions

View File

@ -23,7 +23,7 @@ func main() {
}
defer conn.Close()
conn.SetDeadline(time.Now().Add(1 * time.Hour))
_, err = conn.Write([]byte("hello."))
_, err = conn.Write([]byte("hello.\n"))
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return

1
_examples/tcp/node_modules/.mf/cf.json generated vendored Normal file
View File

@ -0,0 +1 @@
{"clientTcpRtt":4,"longitude":"-87.63830","latitude":"41.90320","tlsCipher":"AEAD-AES256-GCM-SHA384","continent":"NA","asn":6079,"clientAcceptEncoding":"br, gzip, deflate","country":"US","tlsClientAuth":{"certIssuerDNLegacy":"","certIssuerSKI":"","certSubjectDNRFC2253":"","certSubjectDNLegacy":"","certFingerprintSHA256":"","certNotBefore":"","certSKI":"","certSerial":"","certIssuerDN":"","certVerified":"NONE","certNotAfter":"","certSubjectDN":"","certPresented":"0","certRevoked":"0","certIssuerSerial":"","certIssuerDNRFC2253":"","certFingerprintSHA1":""},"tlsExportedAuthenticator":{"clientFinished":"1c90c02fac3c85dd78cfff596c4fd5c980268e2594e9e04a9bf7db554cf1f5f2ad1f9be820c2238a590780c92185018f","clientHandshake":"b48849eda1ee6e209d54b0f7af39b1bcff3837fee871bd8973e64aa60af71a9487fb050e5cdee4caa956499f289a785e","serverHandshake":"7bd22755b98a0d9bd7e1c9035db9ef38e45e33a92b552d7f32be4d10969e6414ac31eb44d6d0f7261b8482e91f0cc769","serverFinished":"c0f8d62f8ee9e60a5c199dc1d5936e3e3acdf82e8a6667bbe88bdcd526f40dc0565ebdf9a821825070bcfef0193d72a6"},"tlsVersion":"TLSv1.3","colo":"ORD","timezone":"America/Chicago","city":"Chicago","httpProtocol":"HTTP/1.1","edgeRequestKeepAliveStatus":1,"requestPriority":"","botManagement":{"corporateProxy":false,"verifiedBot":false,"ja3Hash":"0cce74b0d9b7f8528fb2181588d23793","staticResource":false,"detectionIds":{},"score":4},"clientTrustScore":4,"region":"Illinois","regionCode":"IL","asOrganization":"Astound Broadband","metroCode":"602","postalCode":"60610"}

View File

@ -52,8 +52,6 @@ func (d *Dialer) Dial(ctx context.Context, network, addr string) (net.Conn, erro
sock.reader = sock.socket.Get("readable").Call("getReader")
sock.options = d.opts
sock.goSide, sock.jsSide = net.Pipe()
sock.ctx, sock.cn = context.WithCancel(context.Background())
{
@ -76,9 +74,6 @@ type TCPSocket struct {
readDeadline time.Time
writeDeadline time.Time
goSide net.Conn
jsSide net.Conn
ctx context.Context
cn context.CancelFunc
}
@ -87,21 +82,19 @@ type TCPSocket struct {
// Read can be made to time out and return an error after a fixed
// time limit; see SetDeadline and SetReadDeadline.
func (t *TCPSocket) Read(b []byte) (n int, err error) {
//ctx, cn := context.WithDeadline(t.ctx, t.readDeadline)
//defer cn()
//done := make(chan struct{})
//go func() {
n, err = t.rd.Read(b)
// close(done)
//}()
//select {
//case <-done:
// return
//case <-ctx.Done():
// return 0, os.ErrDeadlineExceeded
//}
return
ctx, cn := context.WithDeadline(t.ctx, t.readDeadline)
defer cn()
done := make(chan struct{})
go func() {
n, err = t.rd.Read(b)
close(done)
}()
select {
case <-done:
return
case <-ctx.Done():
return 0, os.ErrDeadlineExceeded
}
}
// Write writes data to the connection.
@ -189,7 +182,7 @@ func (t *TCPSocket) SetDeadline(deadline time.Time) error {
// and any currently-blocked Read call.
// A zero value for t means Read will not time out.
func (t *TCPSocket) SetReadDeadline(deadline time.Time) error {
t.goSide.SetReadDeadline(deadline)
t.readDeadline = deadline
return nil
}