File tree 3 files changed +43
-2
lines changed 3 files changed +43
-2
lines changed Original file line number Diff line number Diff line change @@ -48,8 +48,8 @@ mergeInto(LibraryManager.library, {
48
48
createSocket : function ( family , type , protocol ) {
49
49
type &= ~ { { { cDefine ( 'SOCK_CLOEXEC' ) | cDefine ( 'SOCK_NONBLOCK' ) } } } ; // Some applications may pass it; it makes no sense for a single process.
50
50
var streaming = type == { { { cDefine ( 'SOCK_STREAM' ) } } } ;
51
- if ( protocol ) {
52
- assert ( streaming == ( protocol == { { { cDefine ( 'IPPROTO_TCP ' ) } } } ) ) ; // if SOCK_STREAM, must be tcp
51
+ if ( streaming && protocol && protocol != { { { cDefine ( 'IPPROTO_TCP' ) } } } ) {
52
+ throw new FS . ErrnoError ( { { { cDefine ( 'EPROTONOSUPPORT ' ) } } } ) ; // if SOCK_STREAM, must be tcp or 0.
53
53
}
54
54
55
55
// create our internal socket structure
Original file line number Diff line number Diff line change
1
+ /*
2
+ * Copyright 2022 The Emscripten Authors. All rights reserved.
3
+ * Emscripten is available under two separate licenses, the MIT license and the
4
+ * University of Illinois/NCSA Open Source License. Both these licenses can be
5
+ * found in the LICENSE file.
6
+ */
7
+
8
+ #include <assert.h>
9
+ #include <errno.h>
10
+ #include <netdb.h>
11
+ #include <sys/socket.h>
12
+ #include <stdio.h>
13
+ #include <stdlib.h>
14
+ #include <unistd.h>
15
+
16
+ int main () {
17
+ int sockfd = socket (AF_INET , SOCK_STREAM , IPPROTO_TCP );
18
+ assert (sockfd >= 0 );
19
+ close (sockfd );
20
+
21
+ sockfd = socket (AF_INET , SOCK_STREAM , 0 );
22
+ assert (sockfd >= 0 );
23
+ close (sockfd );
24
+
25
+ errno = 0 ;
26
+ sockfd = socket (AF_INET , SOCK_STREAM , IPPROTO_UDP );
27
+ assert (sockfd == -1 );
28
+ assert (errno == EPROTONOSUPPORT );
29
+
30
+ errno = 0 ;
31
+ sockfd = socket (AF_INET , SOCK_STREAM , IPPROTO_SCTP );
32
+ assert (sockfd == -1 );
33
+ assert (errno == EPROTONOSUPPORT );
34
+
35
+ puts ("success" );
36
+
37
+ return EXIT_SUCCESS ;
38
+ }
Original file line number Diff line number Diff line change @@ -8991,6 +8991,9 @@ def test_gethostbyname(self):
8991
8991
def test_getprotobyname (self ):
8992
8992
self .do_runf (test_file ('sockets/test_getprotobyname.c' ), 'success' )
8993
8993
8994
+ def test_create_socket (self ):
8995
+ self .do_runf (test_file ('sockets/test_create_socket.c' ), 'success' )
8996
+
8994
8997
def test_socketpair (self ):
8995
8998
self .do_run (r'''
8996
8999
#include <sys/socket.h>
You can’t perform that action at this time.
0 commit comments