Lines Matching refs:ctx
41 lwres_context_initserial() sets the serial number for context *ctx to
53 lwres_context_sendrecv() performs I/O for the context ctx. Data are
147 lwres_context_t *ctx;
162 ctx = malloc_function(arg, sizeof(lwres_context_t));
163 if (ctx == NULL)
169 ctx->malloc = malloc_function;
170 ctx->free = free_function;
171 ctx->arg = arg;
172 ctx->sock = -1;
174 ctx->timeout = LWRES_DEFAULT_TIMEOUT;
176 ctx->serial = time(NULL); /* XXXMLG or BEW */
178 ctx->serial = _time32(NULL);
181 ctx->use_ipv4 = 1;
182 ctx->use_ipv6 = 1;
185 ctx->use_ipv4 = 0;
189 ctx->use_ipv6 = 0;
195 lwres_conf_init(ctx);
197 *contextp = ctx;
209 lwres_context_t *ctx;
213 ctx = *contextp;
216 if (ctx->sock != -1) {
220 (void)close(ctx->sock);
221 ctx->sock = -1;
224 CTXFREE(ctx, sizeof(lwres_context_t));
228 lwres_context_nextserial(lwres_context_t *ctx) {
229 REQUIRE(ctx != NULL);
231 return (ctx->serial++);
234 /*% Sets the serial number for context *ctx to serial. */
236 lwres_context_initserial(lwres_context_t *ctx, lwres_uint32_t serial) {
237 REQUIRE(ctx != NULL);
239 ctx->serial = serial;
244 lwres_context_freemem(lwres_context_t *ctx, void *mem, size_t len) {
253 lwres_context_allocmem(lwres_context_t *ctx, size_t len) {
283 context_connect(lwres_context_t *ctx) {
296 if (ctx->confdata.lwnext != 0) {
297 memmove(&ctx->address, &ctx->confdata.lwservers[0],
299 LWRES_LINK_INIT(&ctx->address, link);
302 memset(&ctx->address, 0, sizeof(ctx->address));
303 ctx->address.family = LWRES_ADDRTYPE_V4;
304 ctx->address.length = 4;
305 ctx->address.address[0] = 127;
306 ctx->address.address[1] = 0;
307 ctx->address.address[2] = 0;
308 ctx->address.address[3] = 1;
311 if (ctx->address.family == LWRES_ADDRTYPE_V4) {
312 memmove(&sin.sin_addr, ctx->address.address,
319 } else if (ctx->address.family == LWRES_ADDRTYPE_V6) {
320 memmove(&sin6.sin6_addr, ctx->address.address,
363 ctx->sock = (int)s;
369 lwres_context_getsocket(lwres_context_t *ctx) {
370 return (ctx->sock);
374 lwres_context_send(lwres_context_t *ctx,
379 if (ctx->sock == -1) {
380 lwresult = context_connect(ctx);
383 INSIST(ctx->sock >= 0);
386 ret = sendto(ctx->sock, sendbase, sendlen, 0, NULL, 0);
396 lwres_context_recv(lwres_context_t *ctx,
406 if (ctx->address.family == LWRES_ADDRTYPE_V4) {
420 ret = recvfrom(ctx->sock, recvbase, recvlen, 0, sa, (void *)&fromlen);
433 if (ctx->address.family == LWRES_ADDRTYPE_V4) {
435 || memcmp(&sin.sin_addr, ctx->address.address,
441 || memcmp(&sin6.sin6_addr, ctx->address.address,
453 /*% performs I/O for the context ctx. */
455 lwres_context_sendrecv(lwres_context_t *ctx,
468 if (ctx->timeout <= 0x7FFFFFFFU)
469 timeout.tv_sec = (int)ctx->timeout;
475 result = lwres_context_send(ctx, sendbase, sendlen);
483 if (ctx->sock >= (int)FD_SETSIZE) {
484 close(ctx->sock);
485 ctx->sock = -1;
491 FD_SET(ctx->sock, &readfds);
492 ret2 = select(ctx->sock + 1, &readfds, NULL, NULL, &timeout);
502 result = lwres_context_recv(ctx, recvbase, recvlen, recvd_len);