Learning redis source code [TCP socket encapsulation]

Source: Internet
Author: User
Tags set socket
Introduction

Redis encapsulation of Linux socket, although it also contains encapsulation of UNIX socket, but generally uses TCP socket. Similar to epoll encapsulation in the previous article, epoll uses the underlying socket function to complete convenient function call encapsulation for some columns.

Source code

Anet. h Anet. c

Analysis

It mainly includes the following encapsulation functions (here only describes the encapsulation functions of TCP socket)

Anettcpconnect: Creates a socket and calls the underlying connect for connection.

Anettcpnonblockconnect: similar to anettcpconnect, but the socket set for connection is not blocked.

Anetread: Call the underlying read to read the content in the socket.

Anetwrite: calls the underlying write to write content to the socket.

Anettcpserver: Creates a listening socket and calls bind and listen to start the server and start listening on the port.

Anettcpaccept: Call accept to receive client connections.

Of course, there are other auxiliary functions, such as anetresolve resolution addresses and some functions that set socket attributes, such as anetnonblock anettcpnodelay anettcpkeepalive anetpeertostring.

Description

The main purpose of the socket encapsulation here is to facilitate redis network call. The functions here are called by the redis network communication implementation to be introduced in the next article.


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.