Project

General

Profile

Feature #9330 ยป 0003-socket-avoid-redundant-fcntl-calls-for-FD-passing.patch

normalperson (Eric Wong), 12/31/2013 11:22 AM

View differences:

ext/socket/ancdata.c
2 2

  
3 3
#include <time.h>
4 4

  
5
int rsock_cmsg_cloexec_state = -1; /* <0: unknown, 0: ignored, >0: working */
6

  
5 7
#if defined(HAVE_STRUCT_MSGHDR_MSG_CONTROL)
6 8
static VALUE rb_cAncillaryData;
7 9

  
......
1416 1418
        int *end = (int *)((char *)cmh + cmh->cmsg_len);
1417 1419
        while ((char *)fdp + sizeof(int) <= (char *)end &&
1418 1420
               (char *)fdp + sizeof(int) <= msg_end) {
1419
            rb_fd_fix_cloexec(*fdp);
1421
            rb_update_max_fd(*fdp);
1420 1422
            close(*fdp);
1421 1423
            fdp++;
1422 1424
        }
......
1459 1461
            VALUE io;
1460 1462
            if (fstat(fd, &stbuf) == -1)
1461 1463
                rb_raise(rb_eSocket, "invalid fd in SCM_RIGHTS");
1462
            rb_fd_fix_cloexec(fd);
1464
            if (rsock_cmsg_cloexec_state < 0)
1465
                rsock_cmsg_cloexec_state = rsock_detect_cloexec(fd);
1466
            if (rsock_cmsg_cloexec_state == 0 || fd <= 2)
1467
                rb_maygvl_fd_fix_cloexec(fd);
1463 1468
            if (S_ISSOCK(stbuf.st_mode))
1464 1469
                io = rsock_init_sock(rb_obj_alloc(rb_cSocket), fd);
1465 1470
            else
ext/socket/rubysocket.h
226 226
#define INET_SOCKS  2
227 227

  
228 228
extern int rsock_do_not_reverse_lookup;
229
extern int rsock_cmsg_cloexec_state;
229 230
#define FMODE_NOREVLOOKUP 0x100
230 231

  
231 232
extern VALUE rb_cBasicSocket;
ext/socket/unixsocket.c
389 389
#if FD_PASSING_BY_MSG_CONTROL
390 390
    memcpy(&fd, CMSG_DATA(&cmsg.hdr), sizeof(int));
391 391
#endif
392
    rb_fd_fix_cloexec(fd);
393 392

  
394
    if (klass == Qnil)
393
    if (rsock_cmsg_cloexec_state < 0)
394
	rsock_cmsg_cloexec_state = rsock_detect_cloexec(fd);
395
    if (rsock_cmsg_cloexec_state == 0 || fd <= 2)
396
	rb_maygvl_fd_fix_cloexec(fd);
397

  
398
    if (klass == Qnil) {
399
	rb_update_max_fd(fd);
395 400
	return INT2FIX(fd);
401
    }
396 402
    else {
397 403
	ID for_fd;
398 404
	int ff_argc;
399
-