c - Meaning of FLAG in socket send and recv -



c - Meaning of FLAG in socket send and recv -

while searching in linux manual page, have found format of send , recv in socket below:

for send,

ssize_t send(int sockfd, const void *buf, size_t len, int flags);

for recv,

ssize_t recv(int sockfd, void *buf, size_t len, int flags);

but not sure trying tell int flags. in 1 sample code have found value of flag 0 (zero). means? meaning of line below in man page?

"the flags argument bitwise or of 0 or more of next flags."

then list of flags:

msg_confirm msg_dontroute . . . etc.

if int flags equal 0, means no flags specified. these optional. reply oring flags - mechanism allow specify more 1 flag - msg_confirm | msg_dontwait specify 2 flags.

or gate: , gate: b out b out 0 0 0 0 0 0 0 1 1 0 1 0 1 0 1 1 0 0 1 1 1 1 1 1

what understand, oring flags set specific bits 1 in int variable. later in code, anding variable specific flags know whether flag set or not. if had specified msg_dontwait flag, code: flags & msg_dontwait homecoming 1, know flag set. let's have how msg_dontwait defined.

enum { ... msg_dontwait = 0x40, /* nonblocking io. */ #define msg_dontwait msg_dontwait ... };

the hex notation 0x40 means 7th bit set 1. below nowadays illustration of bitwise operations socket.c. there's check whether o_nonblock flag set when socket file descriptor created. if so, set on current flags variable 7th bit 1, defined msg_dontwait.

if (sock->file->f_flags & o_nonblock) flags |= msg_dontwait;

a nice reference bitwise operations: http://teaching.idallen.com/cst8214/08w/notes/bit_operations.txt

c linux sockets socketserver

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

c# - Create a Notification Object (Email or Page) At Run Time -- Dependency Injection or Factory -

Set Up Of Common Name Of SSL Certificate To Protect Plesk Panel -