.\" -*- coding: UTF-8 -*- .\" Copyright 2012, Michael Kerrisk .\" Copyright, the authors of the Linux man-pages project .\" .\" SPDX-License-Identifier: Linux-man-pages-copyleft .\" .\"******************************************************************* .\" .\" This file was generated with po4a. Translate the source file. .\" .\"******************************************************************* .TH sendmmsg 2 "8 февраля 2026 г." "Linux man\-pages 6.18" .SH НАИМЕНОВАНИЕ sendmmsg \- отправляет несколько сообщений в сокет .SH БИБЛИОТЕКА Стандартная библиотека языка C (\fIlibc\fP,\ \fI\-lc\fP) .SH СИНТАКСИС .nf \fB#define _GNU_SOURCE\fP /* Смотрите feature_test_macros(7) */ \fB#include \fP .P \fBint sendmmsg(\fPunsigned int n; \fB int \fP\fIsockfd\fP\fB, struct mmsghdr \fP\fImsgvec\fP\fB[\fP\fIn\fP\fB], unsigned int \fP\fIn\fP\fB,\fP \fB int \fP\fIflags\fP\fB);\fP .fi .SH ОПИСАНИЕ .\" See commit 228e548e602061b08ee8e8966f567c12aa079682 Системный вызов \fBsendmmsg\fP() является расширенной версией \fBsendmsg\fP(2), позволяя вызывающему передавать несколько сообщений из сокета, используя только один системный вызов (в некоторых приложениях это позволяет получить выигрыш в производительности). .P Аргумент \fIsockfd\fP представляет собой файловый дескриптор сокета для отправки данных. .P The \fImsgvec\fP argument is a pointer to an array of \fImmsghdr\fP structures. The size of this array is specified in \fIn\fP. .P Структура \fImmsghdr\fP определена в \fI\fP следующим образом: .P .in +4n .EX struct mmsghdr { struct msghdr msg_hdr; /* заголовок сообщения */ unsigned int msg_len; /* кол\-во переданных байт */ }; .EE .in .P Поле \fImsg_hdr\fP представляет собой структуру \fImsghdr\fP, которая описана в \fBsendmsg\fP(2). Поле \fImsg_len\fP используется для возврата количества байт, посланных из сообщения в \fImsg_hdr\fP (т. е., такое же значение, что и возвращаемое значение одиночного вызова \fBsendmsg\fP(2)). .P Аргумент \fIflags\fP содержит объединённые с помощью OR флаги. Флаги те же, что и у \fBsendmsg\fP(2). .P A blocking \fBsendmmsg\fP() call blocks until \fIn\fP messages have been sent. A nonblocking call sends as many messages as possible (up to the limit specified by \fIn\fP) and returns immediately. .P При возврате из \fBsendmmsg\fP(), поля \fImsg_len\fP последующих элементов \fImsgvec\fP обновляются и содержат количество байт, переданных из соответствующего \fImsg_hdr\fP. Возвращаемое вызовом значение равно количеству элементов \fImsgvec\fP, которые были обновлены. .SH "ВОЗВРАЩАЕМОЕ ЗНАЧЕНИЕ" On success, \fBsendmmsg\fP() returns the number of messages sent from \fImsgvec\fP; if this is less than \fIn\fP, the caller can retry with a further \fBsendmmsg\fP() call to send the remaining messages. .P В случае ошибки возвращается \-1, а \fIerrno\fP устанавливается в значение ошибки. .SH ОШИБКИ .\" commit 728ffb86f10873aaf4abd26dde691ee40ae731fe .\" ...only return an error if no datagrams could be sent. .\" If less than the requested number of messages were sent, the application .\" must retry starting at the first failed one and if the problem is .\" persistent the error will be returned. .\" .\" This matches the behavior of other syscalls like read/write - it .\" is not an error if less than the requested number of elements are sent. Возникают те же ошибки что и для \fBsendmsg\fP(2). Ошибка возвращается только, если ни одной дейтаграммы не послано. Смотрите также ДЕФЕКТЫ. .SH СТАНДАРТЫ Linux. .SH ИСТОРИЯ Linux 3.0, glibc 2.14. .SH ПРИМЕЧАНИЯ .\" commit 98382f419f32d2c12d021943b87dea555677144b .\" net: Cap number of elements for sendmmsg .\" .\" To limit the amount of time we can spend in sendmmsg, cap the .\" number of elements to UIO_MAXIOV (currently 1024). .\" .\" For error handling an application using sendmmsg needs to retry at .\" the first unsent message, so capping is simpler and requires less .\" application logic than returning EINVAL. The value specified in \fIn\fP is capped to \fBUIO_MAXIOV\fP (1024). .SH "ПРОГРАММНЫЕ ОШИБКИ" Если после отправки хотя бы одного сообщения произошла ошибка, то вызов завершается успешно и возвращается количество отправленных сообщений. Код ошибки теряется. Вызывающий может повторить передачу, начиная с первого ошибочного сообщения, но нет гарантии, что возвращаемый код ошибки будет совпадать с потерянным в предыдущем вызове. .SH ПРИМЕРЫ В примере далее \fBsendmmsg\fP() используется для отправки \fIonetwo\fP и \fIthree\fP в двух разных дейтаграммах UDP за один системный вызов. Содержимое первой дейтаграммы составляется из пары буферов. .P .\" SRC BEGIN (sendmmsg.c) .EX #define _GNU_SOURCE #include #include #include #include #include #include #include \& int main(void) { int retval; int sockfd; struct iovec msg1[2], msg2; struct mmsghdr msg[2]; struct sockaddr_in addr; \& sockfd = socket(AF_INET, SOCK_DGRAM, 0); if (sockfd == \-1) { perror("socket()"); exit(EXIT_FAILURE); } \& addr.sin_family = AF_INET; addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK); addr.sin_port = htons(1234); if (connect(sockfd, (struct sockaddr *) &addr, sizeof(addr)) == \-1) { perror("connect()"); exit(EXIT_FAILURE); } \& memset(msg1, 0, sizeof(msg1)); msg1[0].iov_base = "one"; msg1[0].iov_len = 3; msg1[1].iov_base = "two"; msg1[1].iov_len = 3; \& memset(&msg2, 0, sizeof(msg2)); msg2.iov_base = "three"; msg2.iov_len = 5; \& memset(msg, 0, sizeof(msg)); msg[0].msg_hdr.msg_iov = msg1; msg[0].msg_hdr.msg_iovlen = 2; \& msg[1].msg_hdr.msg_iov = &msg2; msg[1].msg_hdr.msg_iovlen = 1; \& retval = sendmmsg(sockfd, msg, 2, 0); if (retval == \-1) perror("sendmmsg()"); else printf("%d messages sent\[rs]n", retval); \& exit(0); } .EE .\" SRC END .SH "СМОТРИТЕ ТАКЖЕ" \fBrecvmmsg\fP(2), \fBsendmsg\fP(2), \fBsocket\fP(2), \fBsocket\fP(7) .PP .SH ПЕРЕВОД Русский перевод этой страницы руководства разработал(и) Alexander Golubev , Azamat Hackimov , Hotellook, Nikita , Spiros Georgaras , Vladislav , Yuri Kozlov и Иван Павлов . .PP Этот перевод является свободной программной документацией; он распространяется на условиях общедоступной лицензии GNU (GNU General Public License - GPL, .UR https://www.gnu.org/licenses/gpl-3.0.html .UE версии 3 или более поздней) в отношении авторского права, но БЕЗ КАКИХ-ЛИБО ГАРАНТИЙ. .PP Если вы обнаружите какие-либо ошибки в переводе этой страницы руководства, пожалуйста, сообщите об этом разработчику(ам) по его(их) адресу(ам) электронной почты или по адресу .MT debian-l10n-russian@lists.debian.org списка рассылки русских переводчиков .ME .