@@ -456,36 +456,6 @@ struct Socket[AddrType: Addr, address_family: Int = AF_INET](Representable, Stri
456
456
var remote = self .get_peer_name()
457
457
self ._remote_address = AddrType(remote.host, remote.port)
458
458
459
- # @always_inline
460
- # fn write_bytes(mut self, bytes: Span[Byte]) raises -> None:
461
- # """Write a `Span[Byte]` to this `Writer`.
462
-
463
- # Args:
464
- # bytes: The string slice to write to this Writer. Must NOT be null-terminated.
465
- # """
466
- # if len(bytes) == 0:
467
- # return
468
-
469
- # var bytes_sent = send(self.fd, bytes.unsafe_ptr(), len(bytes), 0)
470
- # # if bytes_sent == -1:
471
- # # abort("Failed to send message")
472
-
473
- # fn write[*Ts: Writable](mut self, *args: *Ts) -> None:
474
- # """Write data to the File Descriptor.
475
-
476
- # Parameters:
477
- # Ts: The types of data to write to the file descriptor.
478
-
479
- # Args:
480
- # args: The data to write to the file descriptor.
481
- # """
482
-
483
- # @parameter
484
- # fn write_arg[T: Writable](arg: T):
485
- # arg.write_to(self)
486
-
487
- # args.each[write_arg]()
488
-
489
459
fn send (self , buffer : Span[Byte]) raises -> Int:
490
460
if buffer[- 1 ] == 0 :
491
461
raise Error(" Socket.send: Buffer must not be null-terminated." )
@@ -526,36 +496,6 @@ struct Socket[AddrType: Addr, address_family: Int = AF_INET](Representable, Stri
526
496
total_bytes_sent += sent
527
497
attempts += 1
528
498
529
- # fn send_to(mut self, src: Span[Byte], address: String, port: Int) raises -> Int:
530
- # """Send data to the a remote address by connecting to the remote socket before sending.
531
- # The socket must be not already be connected to a remote socket.
532
-
533
- # Args:
534
- # src: The data to send.
535
- # address: The IP address to connect to.
536
- # port: The port number to connect to.
537
-
538
- # Returns:
539
- # The number of bytes sent.
540
-
541
- # Raises:
542
- # Error: If sending the data fails.
543
- # """
544
- # sa = build_sockaddr(address, port, self.address_family)
545
- # bytes_sent = sendto(
546
- # self.fd,
547
- # src.unsafe_ptr(),
548
- # len(src),
549
- # 0,
550
- # Pointer.address_of(sa),
551
- # sizeof[sockaddr_in](),
552
- # )
553
-
554
- # if bytes_sent == -1:
555
- # raise Error("Socket.send_to: Failed to send message to remote socket at: " + address + ":" + str(port))
556
-
557
- # return bytes_sent
558
-
559
499
fn _receive (self , mut buffer : Bytes) raises -> Int:
560
500
""" Receive data from the socket into the buffer.
561
501
@@ -615,71 +555,6 @@ struct Socket[AddrType: Addr, address_family: Int = AF_INET](Representable, Stri
615
555
"""
616
556
return self ._receive(buffer)
617
557
618
- # fn receive_from(self, mut buffer: Bytes) raises -> (List[Byte, True], HostPort):
619
- # """Receive data from the socket into the buffer dest.
620
-
621
- # Args:
622
- # buffer: The buffer to read data into.
623
-
624
- # Returns:
625
- # The number of bytes read, the remote address, and an error if one occurred.
626
-
627
- # Raises:
628
- # Error: If reading data from the socket fails.
629
- # """
630
- # remote_address = sockaddr()
631
- # # remote_address_ptr = UnsafePointer[sockaddr].alloc(1)
632
- # remote_address_ptr_size = socklen_t(sizeof[sockaddr]())
633
- # buffer = UnsafePointer[Byte].alloc(size)
634
- # bytes_received = recvfrom(
635
- # self.fd,
636
- # buffer,
637
- # size,
638
- # 0,
639
- # Pointer.address_of(remote_address),
640
- # Pointer.address_of(remote_address_ptr_size),
641
- # )
642
-
643
- # if bytes_received == 0:
644
- # raise "EOF"
645
- # elif bytes_received == -1:
646
- # raise Error("Failed to read from socket, received a -1 response.")
647
-
648
- # remote = convert_sockaddr_to_host_port(remote_address)
649
- # return List[Byte, True](ptr=buffer, length=bytes_received, capacity=size), remote
650
-
651
- # fn receive_from_into(mut self, mut dest: List[Byte, True]) raises -> (Int, HostPort):
652
- # """Receive data from the socket into the buffer dest.
653
-
654
- # Args:
655
- # dest: The buffer to read data into.
656
-
657
- # Returns:
658
- # The number of bytes read, the remote address, and an error if one occurred.
659
-
660
- # Raises:
661
- # Error: If reading data from the socket fails.
662
- # """
663
- # remote_address = sockaddr()
664
- # # remote_address_ptr = UnsafePointer[sockaddr].alloc(1)
665
- # remote_address_ptr_size = socklen_t(sizeof[sockaddr]())
666
- # bytes_read = recvfrom(
667
- # self.fd,
668
- # dest.unsafe_ptr() + len(dest),
669
- # dest.capacity - dest.size,
670
- # 0,
671
- # Pointer.address_of(remote_address),
672
- # Pointer.address_of(remote_address_ptr_size),
673
- # )
674
- # dest.size += bytes_read
675
-
676
- # if bytes_read == 0:
677
- # raise "EOF"
678
- # elif bytes_read == -1:
679
- # raise Error("Socket.receive_from_into: Failed to read from socket, received a -1 response.")
680
-
681
- # return bytes_read, convert_sockaddr_to_host_port(remote_address)
682
-
683
558
fn shutdown (mut self ) raises -> None :
684
559
""" Shut down the socket. The remote end will receive no more data (after queued data is flushed)."""
685
560
try :
0 commit comments