MCPcopy Create free account
hub / github.com/FFmpeg/FFmpeg / start_connect_attempt

Function start_connect_attempt

libavformat/network.c:351–398  ·  view source on GitHub ↗

Returns < 0 on error, 0 on successfully started connection attempt, > 0 for a connection that succeeded already.

Source from the content-addressed store, hash-verified

349// Returns < 0 on error, 0 on successfully started connection attempt,
350// > 0 for a connection that succeeded already.
351static int start_connect_attempt(struct ConnectionAttempt *attempt,
352 struct addrinfo **ptr, int timeout_ms,
353 URLContext *h,
354 int (*customize_fd)(void *, int, int), void *customize_ctx)
355{
356 struct addrinfo *ai = *ptr;
357 int ret;
358
359 *ptr = ai->ai_next;
360
361 attempt->fd = ff_socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol, h);
362 if (attempt->fd < 0)
363 return ff_neterrno();
364 attempt->deadline_us = av_gettime_relative() + timeout_ms * 1000;
365 attempt->addr = ai;
366
367 ff_socket_nonblock(attempt->fd, 1);
368
369 if (customize_fd) {
370 ret = customize_fd(customize_ctx, attempt->fd, ai->ai_family);
371 if (ret) {
372 closesocket(attempt->fd);
373 attempt->fd = -1;
374 return ret;
375 }
376 }
377
378 while ((ret = connect(attempt->fd, ai->ai_addr, ai->ai_addrlen))) {
379 ret = ff_neterrno();
380 switch (ret) {
381 case AVERROR(EINTR):
382 if (ff_check_interrupt(&h->interrupt_callback)) {
383 closesocket(attempt->fd);
384 attempt->fd = -1;
385 return AVERROR_EXIT;
386 }
387 continue;
388 case AVERROR(EINPROGRESS):
389 case AVERROR(EAGAIN):
390 return 0;
391 default:
392 closesocket(attempt->fd);
393 attempt->fd = -1;
394 return ret;
395 }
396 }
397 return 1;
398}
399
400// Try a new connection to another address after 200 ms, as suggested in
401// RFC 8305 (or sooner if an earlier attempt fails).

Callers 1

ff_connect_parallelFunction · 0.85

Calls 6

ff_socketFunction · 0.85
ff_neterrnoFunction · 0.85
av_gettime_relativeFunction · 0.85
ff_socket_nonblockFunction · 0.85
customize_fdFunction · 0.85
ff_check_interruptFunction · 0.85

Tested by

no test coverage detected