SlideShare une entreprise Scribd logo
1  sur  20
Network
sockets
Quick overview
Sockets types
Raw socket
Stream socket (SOCK_STREAM)
Datagram socket (SOCK_DGRAM)
Data types
struct addrinfo
struct sockaddr
struct sockaddr_in
struct in_addr
struct sockaddr_storage
Helper functions
inet_pton() - convert address from str to int
inet_ntop() - convert address from int to str
Address binding
Local addr.port Remote addr.port Description
*.port *.* All local interfaces
laddr.lport *.* Specific local interface
laddr.lport raddr.rport One client
Server init
getaddrinfo() - convert hostname to ip address
socket() - create a socket
bind() - associate with a port to listen on
listen() - marks the socket referred as a passive socket and setups the number of
pending connections
accept() - block waiting on a new connection
getnameinfo() - get host and port as strings
Client init
getaddrinfo() - convert hostname to ip address
socket() - create a socket
connect() - connect to a remote port (optionally)
Communication over TCP sockets
send() - returns number of sent bytes or -1
recv() - returns number of received bytes or 0 (closed conn on a remote side) or -1
Communication over UDP sockets
sendto() - returns number of sent bytes or -1
recvfrom() - returns number of received bytes or -1
OR, if connect() was called, use:
send() - returns number of sent bytes or -1
recv() - returns number of received bytes or -1
Closing socket
close() - close and free
shutdown() - close not free with option:
SHUT_RD
SHUT_RDWR
SHUT_WR
Get info
getpeername() - remote side address
gethostname() - local hostname
Socket settings
Blocking mode - fcntl(O_NONBLOCK)
Multiplexing server
getaddrinfo() - convert hostname to ip address
socket() - create a socket
bind() - associate with a port to listen on
listen() - marks the socket referred as a passive socket and setups the number of
pending connections
select/poll/epoll/kqueue - blocks waiting on multiple connections events
getnameinfo() - get host and port as strings
Multiplexing using select
select(num, readfds, writefds, exceptfds, timeout)
1. Manipulate bitmaps of max size 1024 bits using macros FD_SET, FD_CLR,
FD_ISSET, FD_ZERO
2. Select returns modifies bitmaps thus applications should refill the interest sets
for every call.
3. Thus both application and kernel have to scan entire bitmaps on each call to
figure out interest sets and the result sets.
4. Moreover kernel iterates over interest set to find out which file descriptor is
ready.
Multiplexing using poll
Cons
App and kernel still have to scan to
figure out interest and result fd
sets
Kernel still have to check which fd
of interest are ready as far as
there is no state saved.
API
poll(struct pollfd *fds, int nfds, int timeout)
Pros
Relies on array of file descriptors
instead of bitmaps. Thus no 1024
limit.
Interest and result sets are
separated, so app does not need
to update it each time
Multiplexing using epoll in Linux
API
int epoll_create(int size) - Create
interest set
int epoll_ctl(int epfd, int op, int fd, struct
epoll_event *event) - Add fd
int epoll_wait(int epfd, struct epoll_event
*events, int maxevents, int timeout) -
Wait
Two modes: level triggered and edge
triggered
Pros
Stateful, no scan on each time is required
Multiple interest sets in one process
Cons
Can not add multiple descriptors at once
Multiplexing using kqueue in FreeBSD
API
int kqueue(void);
int kevent(int kq, const struct kevent
*changelist, int nchanges,
struct kevent *eventlist, int nevents,
const struct timespec *timeout);
Pros
Stateful, no scan on each time is
required
Multiple interest sets in one process
Can add multiple descriptors at once
Can work not only for sockets, but for
files, timers, signals, ...
Broadcast
setsockopt (SO_BROADCAST)
References
Using network sockets
Scalable Event Multiplexing: epoll vs. kqueue
The C10K problem
Re: Linux's implementation of poll() not scalable?
How to use epoll? A complete example in C
My blog
Learning Network Programming

Contenu connexe

Tendances

Recent advance in netmap/VALE(mSwitch)
Recent advance in netmap/VALE(mSwitch)Recent advance in netmap/VALE(mSwitch)
Recent advance in netmap/VALE(mSwitch)
micchie
 

Tendances (20)

VLANs in the Linux Kernel
VLANs in the Linux KernelVLANs in the Linux Kernel
VLANs in the Linux Kernel
 
Recent advance in netmap/VALE(mSwitch)
Recent advance in netmap/VALE(mSwitch)Recent advance in netmap/VALE(mSwitch)
Recent advance in netmap/VALE(mSwitch)
 
2015 FOSDEM - OVS Stateful Services
2015 FOSDEM - OVS Stateful Services2015 FOSDEM - OVS Stateful Services
2015 FOSDEM - OVS Stateful Services
 
Why my network does not work? Networking Quiz 2017
Why my network does not work? Networking Quiz 2017Why my network does not work? Networking Quiz 2017
Why my network does not work? Networking Quiz 2017
 
Bypassing ASLR Exploiting CVE 2015-7545
Bypassing ASLR Exploiting CVE 2015-7545Bypassing ASLR Exploiting CVE 2015-7545
Bypassing ASLR Exploiting CVE 2015-7545
 
Network configuration
Network configurationNetwork configuration
Network configuration
 
Networking in linux
Networking in linuxNetworking in linux
Networking in linux
 
3.2 process text streams using filters
3.2 process text streams using filters3.2 process text streams using filters
3.2 process text streams using filters
 
Linux Device Tree
Linux Device TreeLinux Device Tree
Linux Device Tree
 
BPF & Cilium - Turning Linux into a Microservices-aware Operating System
BPF  & Cilium - Turning Linux into a Microservices-aware Operating SystemBPF  & Cilium - Turning Linux into a Microservices-aware Operating System
BPF & Cilium - Turning Linux into a Microservices-aware Operating System
 
Embedded TCP/IP stack for FreeRTOS
Embedded TCP/IP stack for FreeRTOSEmbedded TCP/IP stack for FreeRTOS
Embedded TCP/IP stack for FreeRTOS
 
BPF: Next Generation of Programmable Datapath
BPF: Next Generation of Programmable DatapathBPF: Next Generation of Programmable Datapath
BPF: Next Generation of Programmable Datapath
 
Semtex.c [CVE-2013-2094] - A Linux Privelege Escalation
Semtex.c [CVE-2013-2094] - A Linux Privelege EscalationSemtex.c [CVE-2013-2094] - A Linux Privelege Escalation
Semtex.c [CVE-2013-2094] - A Linux Privelege Escalation
 
Userspace networking
Userspace networkingUserspace networking
Userspace networking
 
Linux Kernel Cryptographic API and Use Cases
Linux Kernel Cryptographic API and Use CasesLinux Kernel Cryptographic API and Use Cases
Linux Kernel Cryptographic API and Use Cases
 
DockerCon 2017 - Cilium - Network and Application Security with BPF and XDP
DockerCon 2017 - Cilium - Network and Application Security with BPF and XDPDockerCon 2017 - Cilium - Network and Application Security with BPF and XDP
DockerCon 2017 - Cilium - Network and Application Security with BPF and XDP
 
The TCP/IP Stack in the Linux Kernel
The TCP/IP Stack in the Linux KernelThe TCP/IP Stack in the Linux Kernel
The TCP/IP Stack in the Linux Kernel
 
101 3.2 process text streams using filters
101 3.2 process text streams using filters101 3.2 process text streams using filters
101 3.2 process text streams using filters
 
101 3.2 process text streams using filters
101 3.2 process text streams using filters101 3.2 process text streams using filters
101 3.2 process text streams using filters
 
Comprehensive XDP Off‌load-handling the Edge Cases
Comprehensive XDP Off‌load-handling the Edge CasesComprehensive XDP Off‌load-handling the Edge Cases
Comprehensive XDP Off‌load-handling the Edge Cases
 

En vedette

From the Telegraph to ARPANET. “Alternative” Networks, Counter Culture, the I...
From the Telegraph to ARPANET. “Alternative” Networks, Counter Culture, the I...From the Telegraph to ARPANET. “Alternative” Networks, Counter Culture, the I...
From the Telegraph to ARPANET. “Alternative” Networks, Counter Culture, the I...
The New School
 
Mac addresses(media access control)
Mac addresses(media access control)Mac addresses(media access control)
Mac addresses(media access control)
Ismail Mukiibi
 

En vedette (20)

Secure communication
Secure communicationSecure communication
Secure communication
 
C++ 11
C++ 11C++ 11
C++ 11
 
Git basics
Git basicsGit basics
Git basics
 
Understanding iptables
Understanding iptablesUnderstanding iptables
Understanding iptables
 
Vagrant
VagrantVagrant
Vagrant
 
History of the personal computer
History of the personal computerHistory of the personal computer
History of the personal computer
 
Understanding DPDK algorithmics
Understanding DPDK algorithmicsUnderstanding DPDK algorithmics
Understanding DPDK algorithmics
 
Understanding DPDK
Understanding DPDKUnderstanding DPDK
Understanding DPDK
 
DPDK Summit - 08 Sept 2014 - Intel - Networking Workloads on Intel Architecture
DPDK Summit - 08 Sept 2014 - Intel - Networking Workloads on Intel ArchitectureDPDK Summit - 08 Sept 2014 - Intel - Networking Workloads on Intel Architecture
DPDK Summit - 08 Sept 2014 - Intel - Networking Workloads on Intel Architecture
 
DPDK Summit 2015 - Intel - Keith Wiles
DPDK Summit 2015 - Intel - Keith WilesDPDK Summit 2015 - Intel - Keith Wiles
DPDK Summit 2015 - Intel - Keith Wiles
 
06 mac address
06 mac address06 mac address
06 mac address
 
Arpanet
ArpanetArpanet
Arpanet
 
From the Telegraph to ARPANET. “Alternative” Networks, Counter Culture, the I...
From the Telegraph to ARPANET. “Alternative” Networks, Counter Culture, the I...From the Telegraph to ARPANET. “Alternative” Networks, Counter Culture, the I...
From the Telegraph to ARPANET. “Alternative” Networks, Counter Culture, the I...
 
Basic socket programming
Basic socket programmingBasic socket programming
Basic socket programming
 
Mac addresses(media access control)
Mac addresses(media access control)Mac addresses(media access control)
Mac addresses(media access control)
 
Intel DPDK Step by Step instructions
Intel DPDK Step by Step instructionsIntel DPDK Step by Step instructions
Intel DPDK Step by Step instructions
 
Network Sockets
Network SocketsNetwork Sockets
Network Sockets
 
Socket Programming Tutorial
Socket Programming TutorialSocket Programming Tutorial
Socket Programming Tutorial
 
Dhcp ppt
Dhcp pptDhcp ppt
Dhcp ppt
 
TCP-IP Reference Model
TCP-IP Reference ModelTCP-IP Reference Model
TCP-IP Reference Model
 

Similaire à Network sockets

Application Layer and Socket Programming
Application Layer and Socket ProgrammingApplication Layer and Socket Programming
Application Layer and Socket Programming
elliando dias
 
Please help with the below 3 questions, the python script is at the.pdf
Please help with the below 3  questions, the python script is at the.pdfPlease help with the below 3  questions, the python script is at the.pdf
Please help with the below 3 questions, the python script is at the.pdf
support58
 

Similaire à Network sockets (20)

Socket programming in c
Socket programming in cSocket programming in c
Socket programming in c
 
Np unit2
Np unit2Np unit2
Np unit2
 
Sockets
Sockets Sockets
Sockets
 
Socket Programming
Socket ProgrammingSocket Programming
Socket Programming
 
Socket Programming
Socket ProgrammingSocket Programming
Socket Programming
 
sockets
socketssockets
sockets
 
Sockets
SocketsSockets
Sockets
 
Application Layer and Socket Programming
Application Layer and Socket ProgrammingApplication Layer and Socket Programming
Application Layer and Socket Programming
 
Socket System Calls
Socket System CallsSocket System Calls
Socket System Calls
 
اسلاید اول جلسه یازدهم کلاس پایتون برای هکرهای قانونی
اسلاید اول جلسه یازدهم کلاس پایتون برای هکرهای قانونیاسلاید اول جلسه یازدهم کلاس پایتون برای هکرهای قانونی
اسلاید اول جلسه یازدهم کلاس پایتون برای هکرهای قانونی
 
Net Programming.ppt
Net Programming.pptNet Programming.ppt
Net Programming.ppt
 
acn-practical_manual-19-20-1 final.pdf
acn-practical_manual-19-20-1 final.pdfacn-practical_manual-19-20-1 final.pdf
acn-practical_manual-19-20-1 final.pdf
 
CCNA 200-120 Exam Quick Notes
CCNA 200-120 Exam Quick NotesCCNA 200-120 Exam Quick Notes
CCNA 200-120 Exam Quick Notes
 
Network Prog.ppt
Network Prog.pptNetwork Prog.ppt
Network Prog.ppt
 
Md13 networking
Md13 networkingMd13 networking
Md13 networking
 
16.) layer 3 (basic tcp ip routing)
16.) layer 3 (basic tcp ip routing)16.) layer 3 (basic tcp ip routing)
16.) layer 3 (basic tcp ip routing)
 
Please help with the below 3 questions, the python script is at the.pdf
Please help with the below 3  questions, the python script is at the.pdfPlease help with the below 3  questions, the python script is at the.pdf
Please help with the below 3 questions, the python script is at the.pdf
 
socket programming
 socket programming  socket programming
socket programming
 
socket programming
socket programming socket programming
socket programming
 
Internet Technology (Practical Questions Paper) [CBSGS - 75:25 Pattern] {2017...
Internet Technology (Practical Questions Paper) [CBSGS - 75:25 Pattern] {2017...Internet Technology (Practical Questions Paper) [CBSGS - 75:25 Pattern] {2017...
Internet Technology (Practical Questions Paper) [CBSGS - 75:25 Pattern] {2017...
 

Dernier

Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
chiefasafspells
 

Dernier (20)

WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
 
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the past
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go Platformless
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare
 

Network sockets

  • 2. Sockets types Raw socket Stream socket (SOCK_STREAM) Datagram socket (SOCK_DGRAM)
  • 3. Data types struct addrinfo struct sockaddr struct sockaddr_in struct in_addr struct sockaddr_storage
  • 4. Helper functions inet_pton() - convert address from str to int inet_ntop() - convert address from int to str
  • 5. Address binding Local addr.port Remote addr.port Description *.port *.* All local interfaces laddr.lport *.* Specific local interface laddr.lport raddr.rport One client
  • 6. Server init getaddrinfo() - convert hostname to ip address socket() - create a socket bind() - associate with a port to listen on listen() - marks the socket referred as a passive socket and setups the number of pending connections accept() - block waiting on a new connection getnameinfo() - get host and port as strings
  • 7. Client init getaddrinfo() - convert hostname to ip address socket() - create a socket connect() - connect to a remote port (optionally)
  • 8. Communication over TCP sockets send() - returns number of sent bytes or -1 recv() - returns number of received bytes or 0 (closed conn on a remote side) or -1
  • 9. Communication over UDP sockets sendto() - returns number of sent bytes or -1 recvfrom() - returns number of received bytes or -1 OR, if connect() was called, use: send() - returns number of sent bytes or -1 recv() - returns number of received bytes or -1
  • 10. Closing socket close() - close and free shutdown() - close not free with option: SHUT_RD SHUT_RDWR SHUT_WR
  • 11. Get info getpeername() - remote side address gethostname() - local hostname
  • 12. Socket settings Blocking mode - fcntl(O_NONBLOCK)
  • 13. Multiplexing server getaddrinfo() - convert hostname to ip address socket() - create a socket bind() - associate with a port to listen on listen() - marks the socket referred as a passive socket and setups the number of pending connections select/poll/epoll/kqueue - blocks waiting on multiple connections events getnameinfo() - get host and port as strings
  • 14. Multiplexing using select select(num, readfds, writefds, exceptfds, timeout) 1. Manipulate bitmaps of max size 1024 bits using macros FD_SET, FD_CLR, FD_ISSET, FD_ZERO 2. Select returns modifies bitmaps thus applications should refill the interest sets for every call. 3. Thus both application and kernel have to scan entire bitmaps on each call to figure out interest sets and the result sets. 4. Moreover kernel iterates over interest set to find out which file descriptor is ready.
  • 15. Multiplexing using poll Cons App and kernel still have to scan to figure out interest and result fd sets Kernel still have to check which fd of interest are ready as far as there is no state saved. API poll(struct pollfd *fds, int nfds, int timeout) Pros Relies on array of file descriptors instead of bitmaps. Thus no 1024 limit. Interest and result sets are separated, so app does not need to update it each time
  • 16. Multiplexing using epoll in Linux API int epoll_create(int size) - Create interest set int epoll_ctl(int epfd, int op, int fd, struct epoll_event *event) - Add fd int epoll_wait(int epfd, struct epoll_event *events, int maxevents, int timeout) - Wait Two modes: level triggered and edge triggered Pros Stateful, no scan on each time is required Multiple interest sets in one process Cons Can not add multiple descriptors at once
  • 17. Multiplexing using kqueue in FreeBSD API int kqueue(void); int kevent(int kq, const struct kevent *changelist, int nchanges, struct kevent *eventlist, int nevents, const struct timespec *timeout); Pros Stateful, no scan on each time is required Multiple interest sets in one process Can add multiple descriptors at once Can work not only for sockets, but for files, timers, signals, ...
  • 19. References Using network sockets Scalable Event Multiplexing: epoll vs. kqueue The C10K problem Re: Linux's implementation of poll() not scalable? How to use epoll? A complete example in C