main_windows.go 661 B

123456789101112131415161718192021222324252627282930313233
  1. //go:build windows
  2. package yu_tcp
  3. import (
  4. yu_sys "gogs.qqck.cn/s/tools/sys"
  5. )
  6. func (t *Tcp) init() {
  7. t.fd = yu_sys.INVALID_SOCKET
  8. }
  9. func (t *Tcp) connect(host string, port int) bool {
  10. t.close()
  11. t.fd = yu_sys.Socket_connect(host, port, t.sec, t.usec)
  12. return t.fd != yu_sys.INVALID_SOCKET
  13. }
  14. func (t *Tcp) send(fd uintptr, buf []byte) bool {
  15. return yu_sys.Socket_write_tcp(fd, buf, t.sec, t.usec)
  16. }
  17. func (t *Tcp) recv(fd uintptr, size int) []byte {
  18. return yu_sys.Socket_read_tcp(fd, size, t.sec, t.usec)
  19. }
  20. func (t *Tcp) close() *Tcp {
  21. if t.fd != yu_sys.INVALID_SOCKET {
  22. yu_sys.Closesocket.Call(t.fd)
  23. t.fd = yu_sys.INVALID_SOCKET
  24. }
  25. return t
  26. }