Skip to content

Commit

Permalink
std/net: adopt new time::Duration
Browse files Browse the repository at this point in the history
  • Loading branch information
mertcandav committed Oct 29, 2024
1 parent f0ad201 commit 367848e
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion std/jule/sema/builtin.jule
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ fn primTypeAlias(ident: str, mut &k: &Type, strict: bool): &TypeAlias {
Ident: ident,
TypeSym: &TypeSym{
Type: &Type{Kind: s},
}
},
}
}

Expand Down
4 changes: 2 additions & 2 deletions std/net/net.jule
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ trait Conn {
io::Reader
io::Writer
io::Closer
fn SetReadTimeout(mut self, timeout: time::DurInt)!
fn SetWriteTimeout(mut self, timeout: time::DurInt)!
fn SetReadTimeout(mut self, timeout: time::Duration)!
fn SetWriteTimeout(mut self, timeout: time::Duration)!
fn Network(self): Network
}

Expand Down
8 changes: 4 additions & 4 deletions std/net/sock.jule
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ fn Connect(network: Network, addr: str)!: Conn {
// Timeout precision is microseconds.
// If the timeout is below one microsecond it will be ignored.
// If timeout is invalid or out of range, throws exceptional with Error.InvalidTimeout.
fn ConnectTimeout(network: Network, addr: str, timeout: time::DurInt)!: Conn {
fn ConnectTimeout(network: Network, addr: str, timeout: time::Duration)!: Conn {
match network {
| Network.Tcp | Network.Tcp4 | Network.Tcp6:
ret tcpConnect(network, addr, timeout) else { error(error) }
Expand All @@ -101,9 +101,9 @@ unsafe fn connectSocketNoTimeout(handle: netHandle, sockAddr: *sys::Sockaddr, so
}
}

fn timevalFromDuration(timeout: time::DurInt): (tv: sys::Timeval, ok: bool) {
sec := i64(time::Duration.Seconds(timeout))
usec := i64(time::Duration.Microseconds(timeout - (time::Duration.Second * time::DurInt(sec))))
fn timevalFromDuration(timeout: time::Duration): (tv: sys::Timeval, ok: bool) {
sec := i64(timeout.Seconds())
usec := i64((timeout - time::Duration(i64(time::Second)*sec)).Microseconds())
ok = sys::NewTimeval(sec, usec, tv)
ret
}
4 changes: 2 additions & 2 deletions std/net/sock_unix.jule
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ fn openSocketBlockingMode(handle: netHandle)! {
}
}

unsafe fn connectSocket(handle: netHandle, sockAddr: *sys::Sockaddr, sockLen: uint, timeout: time::DurInt)! {
unsafe fn connectSocket(handle: netHandle, sockAddr: *sys::Sockaddr, sockLen: uint, timeout: time::Duration)! {
if timeout == 0 {
connectSocketNoTimeout(handle, sockAddr, sockLen) else { error(error) }
ret
Expand Down Expand Up @@ -128,7 +128,7 @@ fn sendto(&conn: UdpConn, &buf: []byte)!: int {
error(lastErrorCode())
}

fn setSocketTimeout(handle: netHandle, scope: int, timeout: time::DurInt)! {
fn setSocketTimeout(handle: netHandle, scope: int, timeout: time::Duration)! {
tv, ok := timevalFromDuration(timeout)
if !ok {
error(Error.InvalidTimeout)
Expand Down
4 changes: 2 additions & 2 deletions std/net/sock_windows.jule
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ fn openSocketBlockingMode(handle: netHandle)! {
setSocketBlockingMode(handle, 0) else { error(error) }
}

unsafe fn connectSocket(handle: netHandle, sockAddr: *sys::Sockaddr, sockLen: uint, timeout: time::DurInt)! {
unsafe fn connectSocket(handle: netHandle, sockAddr: *sys::Sockaddr, sockLen: uint, timeout: time::Duration)! {
if timeout == 0 {
connectSocketNoTimeout(handle, sockAddr, sockLen) else { error(error) }
ret
Expand Down Expand Up @@ -116,7 +116,7 @@ fn sendto(&conn: UdpConn, &buf: []byte)!: int {
error(lastErrorCode())
}

fn setSocketTimeout(handle: netHandle, scope: int, timeout: time::DurInt)! {
fn setSocketTimeout(handle: netHandle, scope: int, timeout: time::Duration)! {
tv, ok := timevalFromDuration(timeout)
if !ok {
error(Error.InvalidTimeout)
Expand Down
4 changes: 2 additions & 2 deletions std/net/tcp_conn.jule
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ impl TcpConn {
// If the timeout is below one microsecond it will be accepted as zero.
// The zero timeout, clears current timeout if exist.
// All exceptionals are error code of implementation.
fn SetReadTimeout(mut self, timeout: time::DurInt)! {
fn SetReadTimeout(mut self, timeout: time::Duration)! {
if self.handle == sys::INVALID_SOCKET {
panic("net: TcpConn.SetReadTimeout: connection is closed")
}
Expand All @@ -84,7 +84,7 @@ impl TcpConn {
// If the timeout is below one microsecond it will be accepted as zero.
// The zero timeout, clears current timeout if exist.
// All exceptionals are error code of implementation.
fn SetWriteTimeout(mut self, timeout: time::DurInt)! {
fn SetWriteTimeout(mut self, timeout: time::Duration)! {
if self.handle == sys::INVALID_SOCKET {
panic("net: TcpConn.SetReadTimeout: connection is closed")
}
Expand Down
4 changes: 2 additions & 2 deletions std/net/tcp_listener.jule
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ impl TcpListener {
}

// Same as TcpListener.Connect, but uses timeout.
static fn ConnectTimeout(addr: str, timeout: time::DurInt)!: &TcpConn {
static fn ConnectTimeout(addr: str, timeout: time::Duration)!: &TcpConn {
ret tcpConnect(Network.Tcp, addr, timeout) else { error(error) }
}

Expand Down Expand Up @@ -219,7 +219,7 @@ fn tcpBind(network: Network, &addr: str)!: &TcpListener {
}
}

fn tcpConnect(network: Network, &addr: str, timeout: time::DurInt)!: &TcpConn {
fn tcpConnect(network: Network, &addr: str, timeout: time::Duration)!: &TcpConn {
mut tcpAddr := TcpAddr.Resolve(network, addr) else { error(error) }
mut handle := netHandle(sys::INVALID_SOCKET)
mut v6 := false
Expand Down
4 changes: 2 additions & 2 deletions std/net/udp_conn.jule
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ impl UdpConn {
// If the timeout is below one microsecond it will be accepted as zero.
// The zero timeout, clears current timeout if exist.
// All exceptionals are error code of implementation.
fn SetReadTimeout(mut self, timeout: time::DurInt)! {
fn SetReadTimeout(mut self, timeout: time::Duration)! {
if self.handle == sys::INVALID_SOCKET {
panic("net: TcpConn.SetReadTimeout: connection is closed")
}
Expand All @@ -90,7 +90,7 @@ impl UdpConn {
// If the timeout is below one microsecond it will be accepted as zero.
// The zero timeout, clears current timeout if exist.
// All exceptionals are error code of implementation.
fn SetWriteTimeout(mut self, timeout: time::DurInt)! {
fn SetWriteTimeout(mut self, timeout: time::Duration)! {
if self.handle == sys::INVALID_SOCKET {
panic("net: TcpConn.SetReadTimeout: connection is closed")
}
Expand Down
2 changes: 1 addition & 1 deletion std/runtime/strconv.jule
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ fn u64ToBuf(mut buf: []byte, mut x: u64): int {

// reverse
i = 0
mut j := n-1
mut j := n - 1
for i < j; i, j = i+1, j-1 {
buf[i], buf[j] = buf[j], buf[i]
}
Expand Down

0 comments on commit 367848e

Please sign in to comment.