tiny httpd

feof

int feof(FILE *stream)

This function returns a non-zero value when End-of-File indicator associated with the stream is set, else zero is returned. 




S_IFMT

this is a bitmask used to extract the file type code from a mode value. 

S_ISDIR int S_ISDIR(mode_t m)

this macro returns non-zero if the file is a directory. 

S_IFDIR

this is the file type constant of a directory file


S_ISCHR(mode)  is equivalent to ((mode & S_IFMT) == S_IFCHR)


S_IXUSR

S_IEXEC  Execute or search permission bit for the owner of the file. Usually 0100. S_IEXEC is an obsolete synonym provided by BSD compatibility. 

S_IXGRP Execute or search permission bit for the group owner of the file

S_IXOTH Execute or search permission bit for other users.


int strcasecmp(const char *s1, const char *s2)

This function is like strcmp, except that differences in case are ignored. How uppercase and lowercase characters are related is determined by currently selected locale. In the standard "C" locale the characters A and a do not match but in a local which regards these characters as parts of the alphabet they do match. 


pid_t

the pid_t data type is a signed integer type which is capable of representing a process ID. In the GNU C library, this is an int. 

fork

create a child process; fork() creates a new process by duplicating the calling process. The new process, referred to as the child, is an exact duplicate of the calling process, referred to as the parent, except for the following points:.......

#include <sys/types.h>

#include <unistd.h>

pid_t fork(void);


int dup2(int old, int new)

this function copies the descriptor old to descriptor number new. 

if old is an invalid descriptor, then dup2 does nothing; it does not close new. Otherwise, the new duplicate of old replaces any previous meaning of descriptor new, as if new were closed first. 

if old and new are different numbers, and old is a valid descriptor number, then dup2 is equivalent to :

close(new);

fcntl(old, F_DUPFD, new)

However, dup2 does this atomically; there is no instant in the middle of calling dup2 at which new is closed and not yet a duplicate of old. 


int putenv(char *string)


PF_INET protocol family协议相关

AF_INET  address family互联网地址

#defind AF_INET PF_INET  socket.h


uint16_t ntohs(uint16_t netshort)

this function converts the uint16_t integer netshort from network byte order to host byte order. 


unit32_t htonl(unit32_t hostlong)

this function converts the unit32_t integer hostlong from host byte order to network byte order. This is used for IPv4 Internet addresses.

 

unit32_t INADDR_ANY

you can use this constant to stand for "any incoming address" when binding to an address. This is the usual address to give in the sin_addr member struct sockaddr_in when you want to accept Internet connections. 


int bind(int socket, struct sockaddr *addr, socklen_t length)

the bind function assigns an address to the socket socket. the addr and length arguments specify the address; the detailed format of the address depends on the namespace. The first part of the address is always the format designator, which specifies a namespace, and says that the address is in the format of that namespace. 

the return value is 0 on success and -1 on failure. 


struct sockaddr

the struct sockaddr type itself has the following members:

short in sa_family

char sa_data[14]


int getsockname(int short, struct sockaddr *addr, socklen_t *length-prt)

The getsockname function returns information about the address of the socket socket in the locations specified by the addr and length-ptr arguments.

The format of the address data depends on the socket namespace. The length of the information is usually fixed for a given namespace, so normally you can know exactly how much space is needed and can provide that much. The usual practice is to allocate a place for the value using the proper data type for the socket's namespace, then cast its address to struct sockaddr * to pass it to getsockname. 

socklen_t is used in all the cases that POSIX changed to use size_t. The only requirement of this type is that it be an unsigned type of at least 32 bits. 


int listen(int socket, int n)

this listen function enables the socket socket to accept connections, thus making it a server socket.  The argument n specifies the length of the queue for pending connections. When the queue fills, new clients attempting to connect fail with ECONNREFUSED until the server calls accept to accept a connection from the queue. 


int strcmp(const char *s1, const char *s2)


int accept(int socket, struct sockaddr *addr, socklen_t *length_ptr)

The accept function waits if there are no connections pedning, unless the socket has nonblocking mode set. 

The addr and length-ptr arguments are used to return information about the name of the client socket that initiated the connection. 

Accepting a connection does not make socket part of the connection. Instead, it creates a new socket which becomes connected. The normal return value of accept is the file descriptor for the new socket.

After accept, the original socket socket remains open and unconnected, and continues listening until you close it. You can accept further connections with socket by calling accept again.


int pthread_create(pthread_t *thread, const pthread_attr_t *attr, void *(*start_routine)(void*), void *arg)

#include <pthread.h>

the pthread_create() function starts a new thread in the calling process. The new thread starts execution by invoking start_routine(); arg is passed as the sole argument of start_routine().


int connect(int socket, struct sockaddr *addr, socklen_t length)

The connect function initiates a connection from the socket with file descriptor socket to the socket whose address is specified by the addr and length arguments. 

Normally, connect waits until the server responds to the request before it returns. You can set nonblocking mode on the socket socket to make connect return immediately without waiting for the response. 


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值