@@ -317,7 +317,7 @@ struct ds_qp {
317317};
318318
319319struct rsocket {
320- int type ;
320+ int type ; /* SOCK_STREAM or SOCK_DGRAM only; flags in fd_flags/fs_flags */
321321 int index ;
322322 fastlock_t slock ;
323323 fastlock_t rlock ;
@@ -654,6 +654,7 @@ static struct rsocket *rs_alloc(struct rsocket *inherited_rs, int type)
654654 return NULL ;
655655
656656 rs -> type = type ;
657+
657658 rs -> index = -1 ;
658659 if (type == SOCK_DGRAM ) {
659660 rs -> udp_sock = -1 ;
@@ -1199,19 +1200,23 @@ int rsocket(int domain, int type, int protocol)
11991200{
12001201 struct rsocket * rs ;
12011202 int index , ret ;
1203+ int socket_type = type & ~(SOCK_CLOEXEC | SOCK_NONBLOCK );
12021204
12031205 if ((domain != AF_INET && domain != AF_INET6 && domain != AF_IB ) ||
1204- (( type != SOCK_STREAM ) && ( type != SOCK_DGRAM ) ) ||
1205- (type == SOCK_STREAM && protocol && protocol != IPPROTO_TCP ) ||
1206- (type == SOCK_DGRAM && protocol && protocol != IPPROTO_UDP ))
1206+ (socket_type != SOCK_STREAM && socket_type != SOCK_DGRAM ) ||
1207+ (( socket_type == SOCK_STREAM ) && protocol && protocol != IPPROTO_TCP ) ||
1208+ (( socket_type == SOCK_DGRAM ) && protocol && protocol != IPPROTO_UDP ))
12071209 return ERR (ENOTSUP );
12081210
12091211 rs_configure ();
1210- rs = rs_alloc (NULL , type );
1212+ rs = rs_alloc (NULL , socket_type );
12111213 if (!rs )
12121214 return ERR (ENOMEM );
12131215
1214- if (type == SOCK_STREAM ) {
1216+ rs -> fd_flags = (type & SOCK_CLOEXEC ) ? FD_CLOEXEC : 0 ;
1217+ rs -> fs_flags = (type & SOCK_NONBLOCK ) ? O_NONBLOCK : 0 ;
1218+
1219+ if (socket_type == SOCK_STREAM ) {
12151220 ret = rdma_create_id (NULL , & rs -> cm_id , rs , RDMA_PS_TCP );
12161221 if (ret )
12171222 goto err ;
@@ -1222,7 +1227,6 @@ int rsocket(int domain, int type, int protocol)
12221227 ret = ds_init (rs , domain );
12231228 if (ret )
12241229 goto err ;
1225-
12261230 index = rs -> udp_sock ;
12271231 }
12281232
@@ -1315,6 +1319,8 @@ static void rs_accept(struct rsocket *rs)
13151319 if (!new_rs )
13161320 goto err ;
13171321 new_rs -> cm_id = cm_id ;
1322+ new_rs -> fd_flags = rs -> fd_flags ;
1323+ new_rs -> fs_flags = rs -> fs_flags ;
13181324
13191325 ret = rs_insert (new_rs , new_rs -> cm_id -> channel -> fd );
13201326 if (ret < 0 )
@@ -3664,7 +3670,7 @@ int rsetsockopt(int socket, int level, int optname,
36643670 rs = idm_lookup (& idm , socket );
36653671 if (!rs )
36663672 return ERR (EBADF );
3667- if (rs -> type == SOCK_DGRAM && level != SOL_RDMA ) {
3673+ if (( rs -> type == SOCK_DGRAM ) && level != SOL_RDMA ) {
36683674 ret = setsockopt (rs -> udp_sock , level , optname , optval , optlen );
36693675 if (ret )
36703676 return ret ;
@@ -3687,8 +3693,8 @@ int rsetsockopt(int socket, int level, int optname,
36873693 opt_on = * (int * ) optval ;
36883694 break ;
36893695 case SO_RCVBUF :
3690- if ((rs -> type == SOCK_STREAM && !rs -> rbuf ) ||
3691- (rs -> type == SOCK_DGRAM && !rs -> qp_list ))
3696+ if ((( rs -> type == SOCK_STREAM ) && !rs -> rbuf ) ||
3697+ (( rs -> type == SOCK_DGRAM ) && !rs -> qp_list ))
36923698 rs -> rbuf_size = (* (uint32_t * ) optval ) << 1 ;
36933699 ret = 0 ;
36943700 break ;
0 commit comments