5555import static com .oracle .graal .python .runtime .PosixConstants .AF_UNSPEC ;
5656import static com .oracle .graal .python .runtime .PosixConstants .AI_PASSIVE ;
5757import static com .oracle .graal .python .runtime .PosixConstants .INADDR_BROADCAST ;
58- import static com .oracle .graal .python .runtime .PosixConstants .SIZEOF_STRUCT_SOCKADDR_UN_SUN_PATH ;
5958import static com .oracle .graal .python .runtime .PosixConstants .SOCK_DGRAM ;
6059import static com .oracle .graal .python .util .PythonUtils .TS_ENCODING ;
6160import static com .oracle .graal .python .util .PythonUtils .arrayCopyOf ;
9089import com .oracle .graal .python .runtime .PosixSupportLibrary .Inet4SockAddr ;
9190import com .oracle .graal .python .runtime .PosixSupportLibrary .Inet6SockAddr ;
9291import com .oracle .graal .python .runtime .PosixSupportLibrary .InvalidAddressException ;
92+ import com .oracle .graal .python .runtime .PosixSupportLibrary .InvalidUnixSocketPathException ;
9393import com .oracle .graal .python .runtime .PosixSupportLibrary .PosixException ;
9494import com .oracle .graal .python .runtime .PosixSupportLibrary .UniversalSockAddr ;
9595import com .oracle .graal .python .runtime .PosixSupportLibrary .UniversalSockAddrLibrary ;
9696import com .oracle .graal .python .runtime .PosixSupportLibrary .UnixSockAddr ;
97+ import com .oracle .graal .python .runtime .PosixSupportLibrary .UnsupportedPosixFeatureException ;
9798import com .oracle .graal .python .runtime .PythonContext ;
9899import com .oracle .graal .python .runtime .exception .PException ;
99100import com .oracle .graal .python .runtime .object .PythonObjectFactory ;
@@ -141,7 +142,7 @@ UniversalSockAddr doInet(VirtualFrame frame, @SuppressWarnings("unused") PSocket
141142 int port = parsePort (frame , caller , asIntNode , inliningTarget , errorProfile , hostAndPort [1 ]);
142143 UniversalSockAddr addr = setIpAddrNode .execute (frame , host , AF_INET .value );
143144 Object posixSupport = context .getPosixSupport ();
144- return posixLib .createUniversalSockAddr (posixSupport , new Inet4SockAddr (port , sockAddrLib .asInet4SockAddr (addr ).getAddress ()));
145+ return posixLib .createUniversalSockAddrInet4 (posixSupport , new Inet4SockAddr (port , sockAddrLib .asInet4SockAddr (addr ).getAddress ()));
145146 }
146147
147148 @ Specialization (guards = "isInet6(socket)" )
@@ -177,7 +178,7 @@ UniversalSockAddr doInet6(VirtualFrame frame, @SuppressWarnings("unused") PSocke
177178 }
178179 UniversalSockAddr addr = setIpAddrNode .execute (frame , host , AF_INET6 .value );
179180 Object posixSupport = context .getPosixSupport ();
180- return posixLib .createUniversalSockAddr (posixSupport , new Inet6SockAddr (port , sockAddrLib .asInet6SockAddr (addr ).getAddress (), flowinfo , scopeid ));
181+ return posixLib .createUniversalSockAddrInet6 (posixSupport , new Inet6SockAddr (port , sockAddrLib .asInet6SockAddr (addr ).getAddress (), flowinfo , scopeid ));
181182 }
182183
183184 @ Specialization (guards = "isUnix(socket)" )
@@ -208,15 +209,14 @@ UniversalSockAddr doUnix(VirtualFrame frame, @SuppressWarnings("unused") PSocket
208209 // not a linux "abstract" address -> needs a terminating zero
209210 path = arrayCopyOf (path , path .length + 1 );
210211 }
211- if (path .length > SIZEOF_STRUCT_SOCKADDR_UN_SUN_PATH .value ) {
212- throw raise (OSError , ErrorMessages .AF_UNIX_PATH_TOO_LONG , caller );
213- }
214212 PythonContext context = PythonContext .get (this );
215213 Object posixSupport = context .getPosixSupport ();
216214 try {
217- return posixLib .createUniversalSockAddr (posixSupport , new UnixSockAddr (path ));
218- } catch (PosixSupportLibrary . UnsupportedPosixFeatureException e ) {
215+ return posixLib .createUniversalSockAddrUnix (posixSupport , new UnixSockAddr (path ));
216+ } catch (UnsupportedPosixFeatureException e ) {
219217 throw raise (OSError , ErrorMessages .AF_UNIX_NOT_SUPPORTED , caller );
218+ } catch (InvalidUnixSocketPathException e ) {
219+ throw raise (OSError , ErrorMessages .AF_UNIX_PATH_TOO_LONG , caller );
220220 }
221221 }
222222
@@ -297,14 +297,14 @@ UniversalSockAddr setipaddr(VirtualFrame frame, byte[] name, int family,
297297 if (family != AF_INET .value && family != AF_UNSPEC .value ) {
298298 throw raise (OSError , ErrorMessages .ADDRESS_FAMILY_MISMATCHED );
299299 }
300- return posixLib .createUniversalSockAddr (posixSupport , new Inet4SockAddr (0 , INADDR_BROADCAST .value ));
300+ return posixLib .createUniversalSockAddrInet4 (posixSupport , new Inet4SockAddr (0 , INADDR_BROADCAST .value ));
301301 }
302302 /* avoid a name resolution in case of numeric address */
303303 /* check for an IPv4 address */
304304 if (family == AF_INET .value || family == AF_UNSPEC .value ) {
305305 byte [] bytes = inetPtoNCachedPNode .execute (inliningTarget , posixLib , posixSupport , AF_INET .value , name );
306306 if (bytes != null ) {
307- return posixLib .createUniversalSockAddr (posixSupport , new Inet4SockAddr (0 , bytes ));
307+ return posixLib .createUniversalSockAddrInet4 (posixSupport , new Inet4SockAddr (0 , bytes ));
308308 }
309309 }
310310 /*
@@ -315,7 +315,7 @@ UniversalSockAddr setipaddr(VirtualFrame frame, byte[] name, int family,
315315 if ((family == AF_INET6 .value || family == AF_UNSPEC .value ) && !hasScopeId (name )) {
316316 byte [] bytes = inetPtoNCachedPNode .execute (inliningTarget , posixLib , posixSupport , AF_INET6 .value , name );
317317 if (bytes != null ) {
318- return posixLib .createUniversalSockAddr (posixSupport , new Inet6SockAddr (0 , bytes , 0 , 0 ));
318+ return posixLib .createUniversalSockAddrInet6 (posixSupport , new Inet6SockAddr (0 , bytes , 0 , 0 ));
319319 }
320320 }
321321 /* perform a name resolution */
0 commit comments