Basic network socket programming just now

Source: Internet
Author: User
The latest basic network socket programming-general Linux technology-Linux programming and kernel information is shown below. Open the door to the basics of network programming for new users, hoping to help new users!
Encapsulate the source code of the read and write functions provided by the system: (the file is saved as iolib. h)
# Include
# Include
# Include
Ssize_t my_read (int fd, void * buf, size_t length)
{
Ssize_t done = length;
While (done> 0)
{
Done = read (fd, buf, length );
If (done! = Length)
If (errno = EINTR)
Done = length;
Else
{
Perror ("fail to read! \ N ");
Return-1;
}
Else
Break;
}
Return done;
}

Ssize_t my_write (int fd, void * buf, size_t length)
{
Ssize_t done = length;
While (done> 0)
{
Done = write (fd, buf, length );
If (done! = Length)
If (errno = EINTR)
Done = length;
Else
{
Perror ("fail to write! \ N ");
Return-1;
}
Else
Break;
}
Return done;
}

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.