Renamed sin to saddr due to name conflict

During building on MSVC 2013 I got a compiler error by a
type conflict for sin:

test-fdleak.c(60) : error C2365: 'sin' : redefinition; previous definition was 'function'
test-fdleak.c(134) : error C2070: 'double (__cdecl *)()': illegal sizeof operand
test-fdleak.c(134) : error C2198: 'evconnlistener_new_bind' : too few arguments for call
test-fdleak.c(148) : error C2070: 'double (__cdecl *)()': illegal sizeof operand
test-fdleak.c(148) : error C2168: 'memcpy' : too few actual parameters for intrinsic function
test-fdleak.c(149) : error C2224: left of '.sin_family' must have struct/union type
test-fdleak.c(212) : error C2070: 'double (__cdecl *)()': illegal sizeof operand
test-fdleak.c(212) : error C2198: 'bufferevent_socket_connect' : too few arguments for call
test-fdleak.c(239) : error C2070: 'double (__cdecl *)()': illegal sizeof operand
test-fdleak.c(239) : error C2168: 'memset' : too few actual parameters for intrinsic function
test-fdleak.c(240) : error C2224: left of '.sin_family' must have struct/union type
test-fdleak.c(241) : error C2224: left of '.sin_addr' must have struct/union type
test-fdleak.c(242) : error C2224: left of '.sin_port' must have struct/union type

The simplest solution to this problem would be to rename
the variable.
This commit is contained in:
Trond Norbye 2014-03-21 11:59:55 +01:00
parent 6a1c4d501b
commit dc82c8d372

View File

@ -57,7 +57,7 @@
#endif #endif
/* Provide storage for the address, both for the server & the clients */ /* Provide storage for the address, both for the server & the clients */
static struct sockaddr_in sin; static struct sockaddr_in saddr;
/* Number of sucessful requests so far */ /* Number of sucessful requests so far */
static int num_requests; static int num_requests;
@ -131,7 +131,7 @@ start_loop(void)
listener = evconnlistener_new_bind(base, listener_accept_cb, NULL, listener = evconnlistener_new_bind(base, listener_accept_cb, NULL,
LEV_OPT_CLOSE_ON_FREE|LEV_OPT_REUSEABLE, LEV_OPT_CLOSE_ON_FREE|LEV_OPT_REUSEABLE,
-1, (struct sockaddr *)&sin, sizeof(sin)); -1, (struct sockaddr *)&saddr, sizeof(saddr));
if (listener == NULL) { if (listener == NULL) {
my_perror("Could not create listener!"); my_perror("Could not create listener!");
exit(1); exit(1);
@ -145,8 +145,8 @@ start_loop(void)
my_perror("getsockname()"); my_perror("getsockname()");
exit(1); exit(1);
} }
memcpy(&sin, &ss, sizeof(sin)); memcpy(&saddr, &ss, sizeof(saddr));
if (sin.sin_family != AF_INET) { if (saddr.sin_family != AF_INET) {
puts("AF mismatch from getsockname()."); puts("AF mismatch from getsockname().");
exit(1); exit(1);
} }
@ -208,8 +208,8 @@ start_client(struct event_base *base)
BEV_OPT_CLOSE_ON_FREE); BEV_OPT_CLOSE_ON_FREE);
bufferevent_setcb(bev, client_read_cb, NULL, client_event_cb, NULL); bufferevent_setcb(bev, client_read_cb, NULL, client_event_cb, NULL);
if (bufferevent_socket_connect(bev, (struct sockaddr *)&sin, if (bufferevent_socket_connect(bev, (struct sockaddr *)&saddr,
sizeof(sin)) < 0) { sizeof(saddr)) < 0) {
my_perror("Could not connect!"); my_perror("Could not connect!");
bufferevent_free(bev); bufferevent_free(bev);
exit(2); exit(2);
@ -236,10 +236,10 @@ main(int argc, char **argv)
#endif #endif
/* Set up an address, used by both client & server. */ /* Set up an address, used by both client & server. */
memset(&sin, 0, sizeof(sin)); memset(&saddr, 0, sizeof(saddr));
sin.sin_family = AF_INET; saddr.sin_family = AF_INET;
sin.sin_addr.s_addr = htonl(0x7f000001); saddr.sin_addr.s_addr = htonl(0x7f000001);
sin.sin_port = 0; /* Tell the implementation to pick a port. */ saddr.sin_port = 0; /* Tell the implementation to pick a port. */
start_loop(); start_loop();