mirror of
https://github.com/libevent/libevent.git
synced 2025-01-31 09:12:55 +08:00
Fix even more win64 warnings: buffer, event_tagging, http, evdns, evrpc
This commit is contained in:
parent
7484df61c9
commit
545a61145c
39
buffer.c
39
buffer.c
@ -146,7 +146,7 @@ static struct evbuffer_chain *evbuffer_expand_singlechain(struct evbuffer *buf,
|
||||
|
||||
#ifdef WIN32
|
||||
static int evbuffer_readfile(struct evbuffer *buf, evutil_socket_t fd,
|
||||
int howmuch);
|
||||
ev_ssize_t howmuch);
|
||||
#else
|
||||
#define evbuffer_readfile evbuffer_read
|
||||
#endif
|
||||
@ -1025,6 +1025,7 @@ done:
|
||||
|
||||
/* reads data from the src buffer to the dst buffer, avoids memcpy as
|
||||
* possible. */
|
||||
/* XXXX should return ev_ssize_t */
|
||||
int
|
||||
evbuffer_remove_buffer(struct evbuffer *src, struct evbuffer *dst,
|
||||
size_t datlen)
|
||||
@ -1054,7 +1055,7 @@ evbuffer_remove_buffer(struct evbuffer *src, struct evbuffer *dst,
|
||||
if (datlen >= src->total_len) {
|
||||
datlen = src->total_len;
|
||||
evbuffer_add_buffer(dst, src);
|
||||
result = datlen;
|
||||
result = (int)datlen; /*XXXX should return ev_ssize_t*/
|
||||
goto done;
|
||||
}
|
||||
|
||||
@ -1102,7 +1103,7 @@ evbuffer_remove_buffer(struct evbuffer *src, struct evbuffer *dst,
|
||||
evbuffer_invoke_callbacks(dst);
|
||||
evbuffer_invoke_callbacks(src);
|
||||
}
|
||||
result = nread;
|
||||
result = (int)nread;/*XXXX should change return type */
|
||||
|
||||
done:
|
||||
EVBUFFER_UNLOCK2(src, dst);
|
||||
@ -1231,11 +1232,11 @@ evbuffer_readline(struct evbuffer *buffer)
|
||||
return evbuffer_readln(buffer, NULL, EVBUFFER_EOL_ANY);
|
||||
}
|
||||
|
||||
static inline int
|
||||
static inline ev_ssize_t
|
||||
evbuffer_strchr(struct evbuffer_ptr *it, const char chr)
|
||||
{
|
||||
struct evbuffer_chain *chain = it->_internal.chain;
|
||||
unsigned i = it->_internal.pos_in_chain;
|
||||
size_t i = it->_internal.pos_in_chain;
|
||||
while (chain != NULL) {
|
||||
char *buffer = (char *)chain->buffer + chain->misalign;
|
||||
char *cp = memchr(buffer+i, chr, chain->off-i);
|
||||
@ -1280,11 +1281,11 @@ find_eol_char(char *s, size_t len)
|
||||
#undef CHUNK_SZ
|
||||
}
|
||||
|
||||
static int
|
||||
static ev_ssize_t
|
||||
evbuffer_find_eol_char(struct evbuffer_ptr *it)
|
||||
{
|
||||
struct evbuffer_chain *chain = it->_internal.chain;
|
||||
unsigned i = it->_internal.pos_in_chain;
|
||||
size_t i = it->_internal.pos_in_chain;
|
||||
while (chain != NULL) {
|
||||
char *buffer = (char *)chain->buffer + chain->misalign;
|
||||
char *cp = find_eol_char(buffer+i, chain->off-i);
|
||||
@ -1308,7 +1309,7 @@ evbuffer_strspn(
|
||||
{
|
||||
int count = 0;
|
||||
struct evbuffer_chain *chain = ptr->_internal.chain;
|
||||
unsigned i = ptr->_internal.pos_in_chain;
|
||||
size_t i = ptr->_internal.pos_in_chain;
|
||||
|
||||
if (!chain)
|
||||
return -1;
|
||||
@ -1346,7 +1347,7 @@ static inline char
|
||||
evbuffer_getchr(struct evbuffer_ptr *it)
|
||||
{
|
||||
struct evbuffer_chain *chain = it->_internal.chain;
|
||||
int off = it->_internal.pos_in_chain;
|
||||
size_t off = it->_internal.pos_in_chain;
|
||||
|
||||
return chain->buffer[chain->misalign + off];
|
||||
}
|
||||
@ -1910,11 +1911,13 @@ evbuffer_expand(struct evbuffer *buf, size_t datlen)
|
||||
#define IOV_TYPE struct iovec
|
||||
#define IOV_PTR_FIELD iov_base
|
||||
#define IOV_LEN_FIELD iov_len
|
||||
#define IOV_LEN_TYPE size_t
|
||||
#else
|
||||
#define NUM_WRITE_IOVEC 16
|
||||
#define IOV_TYPE WSABUF
|
||||
#define IOV_PTR_FIELD buf
|
||||
#define IOV_LEN_FIELD len
|
||||
#define IOV_LEN_TYPE unsigned long
|
||||
#endif
|
||||
#endif
|
||||
#define NUM_READ_IOVEC 4
|
||||
@ -2093,7 +2096,7 @@ evbuffer_read(struct evbuffer *buf, evutil_socket_t fd, int howmuch)
|
||||
ev_ssize_t space = CHAIN_SPACE_LEN(*chainp);
|
||||
if (space < remaining) {
|
||||
(*chainp)->off += space;
|
||||
remaining -= space;
|
||||
remaining -= (int)space;
|
||||
} else {
|
||||
(*chainp)->off += remaining;
|
||||
buf->last_with_datap = chainp;
|
||||
@ -2118,7 +2121,7 @@ done:
|
||||
|
||||
#ifdef WIN32
|
||||
static int
|
||||
evbuffer_readfile(struct evbuffer *buf, evutil_socket_t fd, int howmuch)
|
||||
evbuffer_readfile(struct evbuffer *buf, evutil_socket_t fd, ev_ssize_t howmuch)
|
||||
{
|
||||
int result;
|
||||
int nchains, n;
|
||||
@ -2142,16 +2145,16 @@ evbuffer_readfile(struct evbuffer *buf, evutil_socket_t fd, int howmuch)
|
||||
result = -1;
|
||||
goto done;
|
||||
}
|
||||
n = read(fd, v[0].iov_base, v[0].iov_len);
|
||||
n = read((int)fd, v[0].iov_base, (unsigned int)v[0].iov_len);
|
||||
if (n <= 0) {
|
||||
result = n;
|
||||
goto done;
|
||||
}
|
||||
v[0].iov_len = n;
|
||||
v[0].iov_len = (IOV_LEN_TYPE) n; /* XXXX another problem with big n.*/
|
||||
if (nchains > 1) {
|
||||
n = read(fd, v[1].iov_base, v[1].iov_len);
|
||||
n = read((int)fd, v[1].iov_base, (unsigned int)v[1].iov_len);
|
||||
if (n <= 0) {
|
||||
result = v[0].iov_len;
|
||||
result = (unsigned long) v[0].iov_len;
|
||||
evbuffer_commit_space(buf, v, 1);
|
||||
goto done;
|
||||
}
|
||||
@ -2190,10 +2193,12 @@ evbuffer_write_iovec(struct evbuffer *buffer, evutil_socket_t fd,
|
||||
#endif
|
||||
iov[i].IOV_PTR_FIELD = (void *) (chain->buffer + chain->misalign);
|
||||
if ((size_t)howmuch >= chain->off) {
|
||||
iov[i++].IOV_LEN_FIELD = chain->off;
|
||||
/* XXXcould be problematic when windows supports mmap*/
|
||||
iov[i++].IOV_LEN_FIELD = (IOV_LEN_TYPE)chain->off;
|
||||
howmuch -= chain->off;
|
||||
} else {
|
||||
iov[i++].IOV_LEN_FIELD = howmuch;
|
||||
/* XXXcould be problematic when windows supports mmap*/
|
||||
iov[i++].IOV_LEN_FIELD = (IOV_LEN_TYPE)howmuch;
|
||||
break;
|
||||
}
|
||||
chain = chain->next;
|
||||
|
34
evdns.c
34
evdns.c
@ -1148,7 +1148,7 @@ request_parse(u8 *packet, int length, struct evdns_server_port *port, struct soc
|
||||
goto err;
|
||||
GET16(type);
|
||||
GET16(class);
|
||||
namelen = strlen(tmp_name);
|
||||
namelen = (int)strlen(tmp_name);
|
||||
q = mm_malloc(sizeof(struct evdns_server_question) + namelen);
|
||||
if (!q)
|
||||
goto err;
|
||||
@ -1323,8 +1323,8 @@ server_port_flush(struct evdns_server_port *port)
|
||||
struct server_request *req = port->pending_replies;
|
||||
ASSERT_LOCKED(port);
|
||||
while (req) {
|
||||
int r = sendto(port->socket, req->response, req->response_len, 0,
|
||||
(struct sockaddr*) &req->addr, req->addrlen);
|
||||
int r = sendto(port->socket, req->response, (int)req->response_len, 0,
|
||||
(struct sockaddr*) &req->addr, (ev_socklen_t)req->addrlen);
|
||||
if (r < 0) {
|
||||
int err = evutil_socket_geterror(port->socket);
|
||||
if (EVUTIL_ERR_RW_RETRIABLE(err))
|
||||
@ -1485,7 +1485,7 @@ dnslabel_table_add(struct dnslabel_table *table, const char *label, off_t pos)
|
||||
/* */
|
||||
static off_t
|
||||
dnsname_to_labels(u8 *const buf, size_t buf_len, off_t j,
|
||||
const char *name, const int name_len,
|
||||
const char *name, const size_t name_len,
|
||||
struct dnslabel_table *table) {
|
||||
const char *end = name + name_len;
|
||||
int ref = 0;
|
||||
@ -1516,25 +1516,25 @@ dnsname_to_labels(u8 *const buf, size_t buf_len, off_t j,
|
||||
}
|
||||
name = strchr(name, '.');
|
||||
if (!name) {
|
||||
const unsigned int label_len = end - start;
|
||||
const size_t label_len = end - start;
|
||||
if (label_len > 63) return -1;
|
||||
if ((size_t)(j+label_len+1) > buf_len) return -2;
|
||||
if (table) dnslabel_table_add(table, start, j);
|
||||
buf[j++] = label_len;
|
||||
buf[j++] = (ev_uint8_t)label_len;
|
||||
|
||||
memcpy(buf + j, start, end - start);
|
||||
j += end - start;
|
||||
j += (int)(end - start);
|
||||
break;
|
||||
} else {
|
||||
/* append length of the label. */
|
||||
const unsigned int label_len = name - start;
|
||||
const size_t label_len = name - start;
|
||||
if (label_len > 63) return -1;
|
||||
if ((size_t)(j+label_len+1) > buf_len) return -2;
|
||||
if (table) dnslabel_table_add(table, start, j);
|
||||
buf[j++] = label_len;
|
||||
buf[j++] = (ev_uint8_t)label_len;
|
||||
|
||||
memcpy(buf + j, start, name - start);
|
||||
j += name - start;
|
||||
j += (int)(name - start);
|
||||
/* hop over the '.' */
|
||||
name++;
|
||||
}
|
||||
@ -1564,7 +1564,7 @@ evdns_request_len(const size_t name_len) {
|
||||
/* */
|
||||
/* Returns the amount of space used. Negative on error. */
|
||||
static int
|
||||
evdns_request_data_build(const char *const name, const int name_len,
|
||||
evdns_request_data_build(const char *const name, const size_t name_len,
|
||||
const u16 trans_id, const u16 type, const u16 class,
|
||||
u8 *const buf, size_t buf_len) {
|
||||
off_t j = 0; /* current offset into buf */
|
||||
@ -1885,8 +1885,8 @@ evdns_server_request_respond(struct evdns_server_request *_req, int err)
|
||||
goto done;
|
||||
}
|
||||
|
||||
r = sendto(port->socket, req->response, req->response_len, 0,
|
||||
(struct sockaddr*) &req->addr, req->addrlen);
|
||||
r = sendto(port->socket, req->response, (int)req->response_len, 0,
|
||||
(struct sockaddr*) &req->addr, (ev_socklen_t)req->addrlen);
|
||||
if (r<0) {
|
||||
int sock_err = evutil_socket_geterror(port->socket);
|
||||
if (EVUTIL_ERR_RW_RETRIABLE(sock_err))
|
||||
@ -2907,7 +2907,7 @@ evdns_search_clear(void) {
|
||||
|
||||
static void
|
||||
search_postfix_add(struct evdns_base *base, const char *domain) {
|
||||
int domain_len;
|
||||
size_t domain_len;
|
||||
struct search_domain *sdomain;
|
||||
while (domain[0] == '.') domain++;
|
||||
domain_len = strlen(domain);
|
||||
@ -2921,7 +2921,7 @@ search_postfix_add(struct evdns_base *base, const char *domain) {
|
||||
if (!sdomain) return;
|
||||
memcpy( ((u8 *) sdomain) + sizeof(struct search_domain), domain, domain_len);
|
||||
sdomain->next = base->global_search_state->head;
|
||||
sdomain->len = domain_len;
|
||||
sdomain->len = (int) domain_len;
|
||||
|
||||
base->global_search_state->head = sdomain;
|
||||
}
|
||||
@ -2984,7 +2984,7 @@ search_set_from_hostname(struct evdns_base *base) {
|
||||
/* warning: returns malloced string */
|
||||
static char *
|
||||
search_make_new(const struct search_state *const state, int n, const char *const base_name) {
|
||||
const int base_len = strlen(base_name);
|
||||
const size_t base_len = strlen(base_name);
|
||||
const char need_to_append_dot = base_name[base_len - 1] == '.' ? 0 : 1;
|
||||
struct search_domain *dom;
|
||||
|
||||
@ -3394,7 +3394,7 @@ evdns_get_default_hosts_filename(void)
|
||||
char path[MAX_PATH+1];
|
||||
static const char hostfile[] = "\\drivers\\etc\\hosts";
|
||||
char *path_out;
|
||||
int len_out;
|
||||
size_t len_out;
|
||||
|
||||
if (! SHGetSpecialFolderPathA(NULL, path, CSIDL_SYSTEM, 0))
|
||||
return NULL;
|
||||
|
@ -256,7 +256,8 @@ evtag_marshal_buffer(struct evbuffer *evbuf, ev_uint32_t tag,
|
||||
struct evbuffer *data)
|
||||
{
|
||||
evtag_encode_tag(evbuf, tag);
|
||||
evtag_encode_int(evbuf, evbuffer_get_length(data));
|
||||
/* XXX support more than UINT32_MAX data */
|
||||
evtag_encode_int(evbuf, (ev_uint32_t)evbuffer_get_length(data));
|
||||
evbuffer_add_buffer(evbuf, data);
|
||||
}
|
||||
|
||||
@ -287,7 +288,8 @@ evtag_marshal_int64(struct evbuffer *evbuf, ev_uint32_t tag,
|
||||
void
|
||||
evtag_marshal_string(struct evbuffer *buf, ev_uint32_t tag, const char *string)
|
||||
{
|
||||
evtag_marshal(buf, tag, string, strlen(string));
|
||||
/* TODO support strings longer than UINT32_MAX ? */
|
||||
evtag_marshal(buf, tag, string, (ev_uint32_t)strlen(string));
|
||||
}
|
||||
|
||||
void
|
||||
@ -302,7 +304,7 @@ evtag_marshal_timeval(struct evbuffer *evbuf, ev_uint32_t tag, struct timeval *t
|
||||
#define DECODE_INT_INTERNAL(number, maxnibbles, pnumber, evbuf, offset) \
|
||||
do { \
|
||||
ev_uint8_t *data; \
|
||||
int len = evbuffer_get_length(evbuf) - offset; \
|
||||
ev_ssize_t len = evbuffer_get_length(evbuf) - offset; \
|
||||
int nibbles = 0; \
|
||||
\
|
||||
if (len <= 0) \
|
||||
@ -329,7 +331,7 @@ do { \
|
||||
\
|
||||
*pnumber = number; \
|
||||
\
|
||||
return (len); \
|
||||
return (int)(len); \
|
||||
} while (0)
|
||||
|
||||
/* Internal: decode an integer from an evbuffer, without draining it.
|
||||
|
2
evrpc.c
2
evrpc.c
@ -210,7 +210,7 @@ static char *
|
||||
evrpc_construct_uri(const char *uri)
|
||||
{
|
||||
char *constructed_uri;
|
||||
int constructed_uri_len;
|
||||
size_t constructed_uri_len;
|
||||
|
||||
constructed_uri_len = strlen(EVRPC_URI_PREFIX) + strlen(uri) + 1;
|
||||
if ((constructed_uri = mm_malloc(constructed_uri_len)) == NULL)
|
||||
|
9
http.c
9
http.c
@ -240,7 +240,8 @@ html_replace(char ch, char *buf)
|
||||
char *
|
||||
evhttp_htmlescape(const char *html)
|
||||
{
|
||||
int i, new_size = 0, old_size = strlen(html);
|
||||
int i;
|
||||
size_t new_size = 0, old_size = strlen(html);
|
||||
char *escaped_html, *p;
|
||||
char scratch_space[2];
|
||||
|
||||
@ -762,7 +763,7 @@ evhttp_connection_done(struct evhttp_connection *evcon)
|
||||
static enum message_read_status
|
||||
evhttp_handle_chunked_read(struct evhttp_request *req, struct evbuffer *buf)
|
||||
{
|
||||
int len;
|
||||
ev_ssize_t len;
|
||||
|
||||
while ((len = evbuffer_get_length(buf)) > 0) {
|
||||
if (req->ntoread < 0) {
|
||||
@ -3371,7 +3372,7 @@ bind_socket_ai(struct evutil_addrinfo *ai, int reuse)
|
||||
evutil_make_listen_socket_reuseable(fd);
|
||||
|
||||
if (ai != NULL) {
|
||||
r = bind(fd, ai->ai_addr, ai->ai_addrlen);
|
||||
r = bind(fd, ai->ai_addr, (ev_socklen_t)ai->ai_addrlen);
|
||||
if (r == -1)
|
||||
goto out;
|
||||
}
|
||||
@ -3563,7 +3564,7 @@ bracket_addr_ok(const char *s, const char *eos)
|
||||
} else {
|
||||
/* IPv6, or junk */
|
||||
char buf[64];
|
||||
int n_chars = eos-s-2;
|
||||
ev_ssize_t n_chars = eos-s-2;
|
||||
struct in6_addr in6;
|
||||
if (n_chars >= 64) /* way too long */
|
||||
return 0;
|
||||
|
Loading…
x
Reference in New Issue
Block a user