|
7 | 7 | package net |
8 | 8 |
|
9 | 9 | import ( |
| 10 | + "errors" |
10 | 11 | "time" |
11 | 12 | ) |
12 | 13 |
|
@@ -80,6 +81,102 @@ type Conn interface { |
80 | 81 | SetWriteDeadline(t time.Time) error |
81 | 82 | } |
82 | 83 |
|
| 84 | +type conn struct { |
| 85 | + // TINYGO: no fd defined |
| 86 | +} |
| 87 | + |
| 88 | +// Close closes the connection. |
| 89 | +func (c *conn) Close() error { |
| 90 | + return errors.New("conn.Close not implemented") |
| 91 | +} |
| 92 | + |
| 93 | +// LocalAddr returns the local network address. |
| 94 | +// The Addr returned is shared by all invocations of LocalAddr, so |
| 95 | +// do not modify it. |
| 96 | +func (c *conn) LocalAddr() Addr { |
| 97 | + // TINYGO: not implemented |
| 98 | + return nil |
| 99 | +} |
| 100 | + |
| 101 | +// SetDeadline implements the Conn SetDeadline method. |
| 102 | +func (c *conn) SetDeadline(t time.Time) error { |
| 103 | + return errors.New("conn.SetDeadline not implemented") |
| 104 | +} |
| 105 | + |
| 106 | +// SetReadDeadline implements the Conn SetReadDeadline method. |
| 107 | +func (c *conn) SetReadDeadline(t time.Time) error { |
| 108 | + return errors.New("conn.SetReadDeadline not implemented") |
| 109 | +} |
| 110 | + |
| 111 | +// SetWriteDeadline implements the Conn SetWriteDeadline method. |
| 112 | +func (c *conn) SetWriteDeadline(t time.Time) error { |
| 113 | + return errors.New("conn.SetWriteDeadline not implemented") |
| 114 | +} |
| 115 | + |
| 116 | +// PacketConn is a generic packet-oriented network connection. |
| 117 | +// |
| 118 | +// Multiple goroutines may invoke methods on a PacketConn simultaneously. |
| 119 | +type PacketConn interface { |
| 120 | + // ReadFrom reads a packet from the connection, |
| 121 | + // copying the payload into p. It returns the number of |
| 122 | + // bytes copied into p and the return address that |
| 123 | + // was on the packet. |
| 124 | + // It returns the number of bytes read (0 <= n <= len(p)) |
| 125 | + // and any error encountered. Callers should always process |
| 126 | + // the n > 0 bytes returned before considering the error err. |
| 127 | + // ReadFrom can be made to time out and return an error after a |
| 128 | + // fixed time limit; see SetDeadline and SetReadDeadline. |
| 129 | + ReadFrom(p []byte) (n int, addr Addr, err error) |
| 130 | + |
| 131 | + // WriteTo writes a packet with payload p to addr. |
| 132 | + // WriteTo can be made to time out and return an Error after a |
| 133 | + // fixed time limit; see SetDeadline and SetWriteDeadline. |
| 134 | + // On packet-oriented connections, write timeouts are rare. |
| 135 | + WriteTo(p []byte, addr Addr) (n int, err error) |
| 136 | + |
| 137 | + // Close closes the connection. |
| 138 | + // Any blocked ReadFrom or WriteTo operations will be unblocked and return errors. |
| 139 | + Close() error |
| 140 | + |
| 141 | + // LocalAddr returns the local network address, if known. |
| 142 | + LocalAddr() Addr |
| 143 | + |
| 144 | + // SetDeadline sets the read and write deadlines associated |
| 145 | + // with the connection. It is equivalent to calling both |
| 146 | + // SetReadDeadline and SetWriteDeadline. |
| 147 | + // |
| 148 | + // A deadline is an absolute time after which I/O operations |
| 149 | + // fail instead of blocking. The deadline applies to all future |
| 150 | + // and pending I/O, not just the immediately following call to |
| 151 | + // Read or Write. After a deadline has been exceeded, the |
| 152 | + // connection can be refreshed by setting a deadline in the future. |
| 153 | + // |
| 154 | + // If the deadline is exceeded a call to Read or Write or to other |
| 155 | + // I/O methods will return an error that wraps os.ErrDeadlineExceeded. |
| 156 | + // This can be tested using errors.Is(err, os.ErrDeadlineExceeded). |
| 157 | + // The error's Timeout method will return true, but note that there |
| 158 | + // are other possible errors for which the Timeout method will |
| 159 | + // return true even if the deadline has not been exceeded. |
| 160 | + // |
| 161 | + // An idle timeout can be implemented by repeatedly extending |
| 162 | + // the deadline after successful ReadFrom or WriteTo calls. |
| 163 | + // |
| 164 | + // A zero value for t means I/O operations will not time out. |
| 165 | + SetDeadline(t time.Time) error |
| 166 | + |
| 167 | + // SetReadDeadline sets the deadline for future ReadFrom calls |
| 168 | + // and any currently-blocked ReadFrom call. |
| 169 | + // A zero value for t means ReadFrom will not time out. |
| 170 | + SetReadDeadline(t time.Time) error |
| 171 | + |
| 172 | + // SetWriteDeadline sets the deadline for future WriteTo calls |
| 173 | + // and any currently-blocked WriteTo call. |
| 174 | + // Even if write times out, it may return n > 0, indicating that |
| 175 | + // some of the data was successfully written. |
| 176 | + // A zero value for t means WriteTo will not time out. |
| 177 | + SetWriteDeadline(t time.Time) error |
| 178 | +} |
| 179 | + |
83 | 180 | // A Listener is a generic network listener for stream-oriented protocols. |
84 | 181 | // |
85 | 182 | // Multiple goroutines may invoke methods on a Listener simultaneously. |
|
0 commit comments