grpc
third_party
cares
cares
src
lib
ares_writev.c
Go to the documentation of this file.
1
2
3
/* Copyright 1998 by the Massachusetts Institute of Technology.
4
*
5
* Permission to use, copy, modify, and distribute this
6
* software and its documentation for any purpose and without
7
* fee is hereby granted, provided that the above copyright
8
* notice appear in all copies and that both that copyright
9
* notice and this permission notice appear in supporting
10
* documentation, and that the name of M.I.T. not be used in
11
* advertising or publicity pertaining to distribution of the
12
* software without specific, written prior permission.
13
* M.I.T. makes no representations about the suitability of
14
* this software for any purpose. It is provided "as is"
15
* without express or implied warranty.
16
*/
17
18
#include "
ares_setup.h
"
19
20
#ifdef HAVE_LIMITS_H
21
# include <limits.h>
22
#endif
23
24
#include "
ares.h
"
25
#include "
ares_private.h
"
26
27
#ifndef HAVE_WRITEV
28
ares_ssize_t
ares_writev
(
ares_socket_t
s,
const
struct
iovec
*
iov
,
int
iovcnt)
29
{
30
char
*
buffer
, *bp;
31
int
i
;
32
size_t
bytes
= 0;
33
ares_ssize_t
result
;
34
35
/* Validate iovcnt */
36
if
(iovcnt <= 0)
37
{
38
SET_ERRNO
(EINVAL);
39
return
(-1);
40
}
41
42
/* Validate and find the sum of the iov_len values in the iov array */
43
for
(
i
= 0;
i
< iovcnt;
i
++)
44
{
45
if
(
iov
[
i
].iov_len > INT_MAX -
bytes
)
46
{
47
SET_ERRNO
(EINVAL);
48
return
(-1);
49
}
50
bytes
+=
iov
[
i
].iov_len;
51
}
52
53
if
(
bytes
== 0)
54
return
(0);
55
56
/* Allocate a temporary buffer to hold the data */
57
buffer
=
ares_malloc
(
bytes
);
58
if
(!
buffer
)
59
{
60
SET_ERRNO
(ENOMEM);
61
return
(-1);
62
}
63
64
/* Copy the data into buffer */
65
for
(bp =
buffer
,
i
= 0;
i
< iovcnt; ++
i
)
66
{
67
memcpy
(bp,
iov
[
i
].iov_base,
iov
[
i
].iov_len);
68
bp +=
iov
[
i
].iov_len;
69
}
70
71
/* Send buffer contents */
72
result
= swrite(s,
buffer
,
bytes
);
73
74
ares_free
(
buffer
);
75
76
return
(
result
);
77
}
78
#endif
79
_gevent_test_main.result
result
Definition:
_gevent_test_main.py:96
ares.h
ares_writev
ares_ssize_t ares_writev(ares_socket_t s, const struct iovec *iov, int iovcnt)
Definition:
ares_writev.c:28
iov
static uv_buf_t iov
Definition:
libuv/docs/code/uvcat/main.c:15
memcpy
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))
ares_malloc
void *(* ares_malloc)(size_t size)=default_malloc
Definition:
ares_library_init.c:58
buffer
char buffer[1024]
Definition:
libuv/docs/code/idle-compute/main.c:8
ares_setup.h
iovec
Definition:
gsec.h:33
bytes
uint8 bytes[10]
Definition:
bloaty/third_party/protobuf/src/google/protobuf/io/coded_stream_unittest.cc:153
ares_socket_t
int ares_socket_t
Definition:
ares.h:229
ares_free
void(* ares_free)(void *ptr)=default_free
Definition:
ares_library_init.c:60
SET_ERRNO
#define SET_ERRNO(x)
Definition:
setup_once.h:441
ares_private.h
ares_ssize_t
CARES_TYPEOF_ARES_SSIZE_T ares_ssize_t
Definition:
ares_build.h:210
i
uint64_t i
Definition:
abseil-cpp/absl/container/btree_benchmark.cc:230
grpc
Author(s):
autogenerated on Fri May 16 2025 02:57:43