mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
net/openssl/websocket: implement io.Writer (#8980)
This commit is contained in:
@@ -74,11 +74,11 @@ pub fn new() FTP {
|
||||
return f
|
||||
}
|
||||
|
||||
fn (mut zftp FTP) write(data string) ? {
|
||||
fn (mut zftp FTP) write(data string) ?int {
|
||||
$if debug {
|
||||
println('FTP.v >>> $data')
|
||||
}
|
||||
zftp.conn.write('$data\r\n'.bytes()) ?
|
||||
return zftp.conn.write('$data\r\n'.bytes())
|
||||
}
|
||||
|
||||
fn (mut zftp FTP) read() ?(int, string) {
|
||||
|
@@ -33,7 +33,7 @@ pub fn (mut c TcpConn) close() ? {
|
||||
}
|
||||
|
||||
// write_ptr blocks and attempts to write all data
|
||||
pub fn (mut c TcpConn) write_ptr(b byteptr, len int) ? {
|
||||
pub fn (mut c TcpConn) write_ptr(b byteptr, len int) ?int {
|
||||
$if trace_tcp ? {
|
||||
eprintln(
|
||||
'>>> TcpConn.write_ptr | c.sock.handle: $c.sock.handle | b: ${ptr_str(b)} len: $len |\n' +
|
||||
@@ -57,17 +57,17 @@ pub fn (mut c TcpConn) write_ptr(b byteptr, len int) ? {
|
||||
}
|
||||
total_sent += sent
|
||||
}
|
||||
return total_sent
|
||||
}
|
||||
return none
|
||||
}
|
||||
|
||||
// write blocks and attempts to write all data
|
||||
pub fn (mut c TcpConn) write(bytes []byte) ? {
|
||||
pub fn (mut c TcpConn) write(bytes []byte) ?int {
|
||||
return c.write_ptr(bytes.data, bytes.len)
|
||||
}
|
||||
|
||||
// write_str blocks and attempts to write all data
|
||||
pub fn (mut c TcpConn) write_str(s string) ? {
|
||||
pub fn (mut c TcpConn) write_str(s string) ?int {
|
||||
return c.write_ptr(s.str, s.len)
|
||||
}
|
||||
|
||||
|
@@ -45,23 +45,23 @@ fn resolve_wrapper(raddr string) ?Addr {
|
||||
return x
|
||||
}
|
||||
|
||||
pub fn (mut c UdpConn) write_ptr(b byteptr, len int) ? {
|
||||
pub fn (mut c UdpConn) write_ptr(b byteptr, len int) ?int {
|
||||
remote := c.sock.remote() or { return err_no_udp_remote }
|
||||
return c.write_to_ptr(remote, b, len)
|
||||
}
|
||||
|
||||
pub fn (mut c UdpConn) write(buf []byte) ? {
|
||||
pub fn (mut c UdpConn) write(buf []byte) ?int {
|
||||
return c.write_ptr(buf.data, buf.len)
|
||||
}
|
||||
|
||||
pub fn (mut c UdpConn) write_str(s string) ? {
|
||||
pub fn (mut c UdpConn) write_str(s string) ?int {
|
||||
return c.write_ptr(s.str, s.len)
|
||||
}
|
||||
|
||||
pub fn (mut c UdpConn) write_to_ptr(addr Addr, b byteptr, len int) ? {
|
||||
pub fn (mut c UdpConn) write_to_ptr(addr Addr, b byteptr, len int) ?int {
|
||||
res := C.sendto(c.sock.handle, b, len, 0, &addr.addr, addr.len)
|
||||
if res >= 0 {
|
||||
return none
|
||||
return res
|
||||
}
|
||||
code := error_code()
|
||||
if code == int(error_ewouldblock) {
|
||||
@@ -74,12 +74,12 @@ pub fn (mut c UdpConn) write_to_ptr(addr Addr, b byteptr, len int) ? {
|
||||
}
|
||||
|
||||
// write_to blocks and writes the buf to the remote addr specified
|
||||
pub fn (mut c UdpConn) write_to(addr Addr, buf []byte) ? {
|
||||
pub fn (mut c UdpConn) write_to(addr Addr, buf []byte) ?int {
|
||||
return c.write_to_ptr(addr, buf.data, buf.len)
|
||||
}
|
||||
|
||||
// write_to_string blocks and writes the buf to the remote addr specified
|
||||
pub fn (mut c UdpConn) write_to_string(addr Addr, s string) ? {
|
||||
pub fn (mut c UdpConn) write_to_string(addr Addr, s string) ?int {
|
||||
return c.write_to_ptr(addr, s.str, s.len)
|
||||
}
|
||||
|
||||
|
@@ -170,7 +170,7 @@ pub fn (mut c StreamConn) close() ? {
|
||||
}
|
||||
|
||||
// write_ptr blocks and attempts to write all data
|
||||
pub fn (mut c StreamConn) write_ptr(b byteptr, len int) ? {
|
||||
pub fn (mut c StreamConn) write_ptr(b byteptr, len int) ?int {
|
||||
$if trace_unix ? {
|
||||
eprintln(
|
||||
'>>> StreamConn.write_ptr | c.sock.handle: $c.sock.handle | b: ${ptr_str(b)} len: $len |\n' +
|
||||
@@ -194,17 +194,17 @@ pub fn (mut c StreamConn) write_ptr(b byteptr, len int) ? {
|
||||
}
|
||||
total_sent += sent
|
||||
}
|
||||
return total_sent
|
||||
}
|
||||
return none
|
||||
}
|
||||
|
||||
// write blocks and attempts to write all data
|
||||
pub fn (mut c StreamConn) write(bytes []byte) ? {
|
||||
pub fn (mut c StreamConn) write(bytes []byte) ?int {
|
||||
return c.write_ptr(bytes.data, bytes.len)
|
||||
}
|
||||
|
||||
// write_str blocks and attempts to write all data
|
||||
pub fn (mut c StreamConn) write_str(s string) ? {
|
||||
pub fn (mut c StreamConn) write_str(s string) ?int {
|
||||
return c.write_ptr(s.str, s.len)
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user