Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion spec/std/socket/address_spec.cr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require "spec"
require "socket"
require "socket/address"

describe Socket::Address do
describe ".parse" do
Expand Down
2 changes: 1 addition & 1 deletion spec/std/socket/addrinfo_spec.cr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require "spec"
require "socket"
require "socket/addrinfo"

describe Socket::Addrinfo do
describe ".resolve" do
Expand Down
42 changes: 8 additions & 34 deletions src/socket.cr
Original file line number Diff line number Diff line change
@@ -1,42 +1,10 @@
require "c/arpa/inet"
require "c/netdb"
require "c/netinet/in"
require "c/netinet/tcp"
require "c/sys/socket"
require "c/sys/un"
require "./socket/addrinfo"

class Socket < IO
include IO::Buffered
include IO::Syscall

class Error < Exception
end

enum Type
STREAM = LibC::SOCK_STREAM
DGRAM = LibC::SOCK_DGRAM
RAW = LibC::SOCK_RAW
SEQPACKET = LibC::SOCK_SEQPACKET
end

enum Protocol
IP = LibC::IPPROTO_IP
TCP = LibC::IPPROTO_TCP
UDP = LibC::IPPROTO_UDP
RAW = LibC::IPPROTO_RAW
ICMP = LibC::IPPROTO_ICMP
end

enum Family : LibC::SaFamilyT
UNSPEC = LibC::AF_UNSPEC
UNIX = LibC::AF_UNIX
INET = LibC::AF_INET
INET6 = LibC::AF_INET6
end

# :nodoc:
SOMAXCONN = 128

getter fd : Int32

@read_event : Event::Event?
Expand Down Expand Up @@ -596,4 +564,10 @@ class Socket < IO
end
end

require "./socket/*"
require "./socket/ip_socket"
require "./socket/server"
require "./socket/tcp_socket"
require "./socket/tcp_server"
require "./socket/unix_socket"
require "./socket/unix_server"
require "./socket/udp_socket"
7 changes: 6 additions & 1 deletion src/socket/address.cr
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
require "socket"
require "uri"
require "c/arpa/inet"
require "c/netdb"
require "c/netinet/in"
require "c/netinet/tcp"
require "c/sys/un"
require "./common"

class Socket
abstract struct Address
Expand Down
1 change: 1 addition & 0 deletions src/socket/addrinfo.cr
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require "uri/punycode"
require "./address"

class Socket
# Domain name resolver.
Expand Down
28 changes: 28 additions & 0 deletions src/socket/common.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
class Socket < IO
class Error < Exception
end

enum Type
STREAM = LibC::SOCK_STREAM
DGRAM = LibC::SOCK_DGRAM
RAW = LibC::SOCK_RAW
SEQPACKET = LibC::SOCK_SEQPACKET
end

enum Protocol
IP = LibC::IPPROTO_IP
TCP = LibC::IPPROTO_TCP
UDP = LibC::IPPROTO_UDP
RAW = LibC::IPPROTO_RAW
ICMP = LibC::IPPROTO_ICMP
end

enum Family : LibC::SaFamilyT
UNSPEC = LibC::AF_UNSPEC
UNIX = LibC::AF_UNIX
INET = LibC::AF_INET
INET6 = LibC::AF_INET6
end

SOMAXCONN = 128
end