Some special usages of TCP/UDP and transceiver interfaces

Source: Internet
Author: User

1.UDP the difference between using the Connect function and not using the Connect function

* No longer use sendto/recvfrom, but only write/read or SEND/RECV, which means that the destination IP cannot be specified when sending and receiving data

* Asynchronous errors raised by connected UDP are returned to the process in which they are located, while non-connected UDP does not receive asynchronous errors

* Connected UDP has high transceiver efficiency. Because the non-connected UDP is sending and receiving data, the connection process needs to be performed before the data is sent and received, and then the connection is unblocked.

* UDP can call connect multiple times to specify a new IP address and port, or it can be disconnected


2.3 Ways to control timeout for all blocking ports such as Recvfrom/sendto,read/write,recv/send,accept,connect

* Select Timeout exit Select.io can be driven not only with Select, but also with signal Sigio (asynchronous IO), which is emitted when any event occurs on Io

* The alarm timeout will receive the SIGALRM signal while the current blocking port returns a ERRNO==EINTR error

* setsockopt setting socket option: So_rcvtimeo/so_sndtimeo

Non-blocking settings:

int Val=fcntl (fd,f_getfl,0);

Fcntl (fd,f_setfl,val| O_nonblock);

3. Parameters for Recvfrom/sendto,read/write,recv/send read-write interface flags flags

* 0 does not have any special meaning

* Msg_dontroute send and receive data, do not need to perform a route lookup, tell the route is within the LAN

* Msg_dontwait perform non-blocking send and receive operations only this time

* Msg_oob indicates that data is sent or received out of band, only one byte on the TCP connection can be transmitted as out-of-band data

* Msg_peek is only useful for receiving data, see how much data is already readable in the cache

* Msg_waitall only useful for receiving data, reading to a specified number of data will return 000


4. Aggregation and dispersion Readv/writev functions: Any file descriptor can be manipulated

#include <sys/uio.h>

size_t readv (int fd,const struct IOVEC *iov,int iovcnt);

size_t writev (int fd,const struct IOVEC *iov,int iovcnt); If successful, returns the number of bytes read and written, failing to return 1

struct iovec{

void *iov_base; //starting Address of buffer

size_t Iov_len; //sizeof of buffer

}

This article from "Tech record" blog, declined reprint!

Some special usages of TCP/UDP and transceiver interfaces

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.