Fix a socket connection problem

This commit is contained in:
Shunsuke Shibayama 2023-01-24 19:57:43 +09:00
parent 4579c86414
commit 64d53a39ce
7 changed files with 101 additions and 5 deletions

View file

@ -252,10 +252,7 @@ impl<Checker: BuildRunnable> Server<Checker> {
// NG: f(proc:= i: T): U -> ... // NG: f(proc:= i: T): U -> ...
// OK: f proc:= (i: T): U -> ... // OK: f proc:= (i: T): U -> ...
let (name, col_begin) = if arg_is_lambda { let (name, col_begin) = if arg_is_lambda {
( (format!(" {name}"), col_begin.saturating_sub(1))
format!(" {name}"),
col_begin.saturating_sub(1),
)
} else { } else {
(name.to_string(), col_begin) (name.to_string(), col_begin)
}; };

View file

@ -11,8 +11,8 @@ use erg_common::python_util::BUILTIN_PYTHON_MODS;
use erg_common::set::Set; use erg_common::set::Set;
use erg_common::traits::{Locational, Stream}; use erg_common::traits::{Locational, Stream};
use erg_common::vis::Visibility; use erg_common::vis::Visibility;
use erg_common::{enum_unwrap, get_hash, log, set};
use erg_common::Str; use erg_common::Str;
use erg_common::{enum_unwrap, get_hash, log, set};
use ast::{Decorator, DefId, Identifier, OperationKind, SimpleTypeSpec, VarName}; use ast::{Decorator, DefId, Identifier, OperationKind, SimpleTypeSpec, VarName};
use erg_parser::ast::{self, ConstIdentifier}; use erg_parser::ast::{self, ConstIdentifier};

View file

@ -1,6 +1,10 @@
.path = pyimport "path" .path = pyimport "path"
# .PathLike: ClassType # .PathLike: ClassType
'''
The name of the operating system dependent module imported. The following names have currently been registered:
'posix', 'nt', 'java'.
'''
.name: Str .name: Str
.chdir!: (path: PathLike, ) => NoneType .chdir!: (path: PathLike, ) => NoneType

View file

@ -1,2 +1,84 @@
.AddressFamily: ClassType
.AddressFamily <: Nat
.AF_ALG: .AddressFamily # unix only
.AF_APPLETALK: .AddressFamily
.AF_ASH: .AddressFamily # unix only
.AF_ATMPVC: .AddressFamily # unix only
.AF_ATMSVC: .AddressFamily # unix only
.AF_AX25: .AddressFamily
.AF_BRIDGE: .AddressFamily # unix only
.AF_BLUETOOTH: .AddressFamily
.AF_CAN: .AddressFamily # unix only
.AF_DECnet: .AddressFamily
.AF_ECONET: .AddressFamily # unix only
.AF_INET: .AddressFamily
.AF_INET6: .AddressFamily
.AF_IPX: .AddressFamily
.AF_IRDA: .AddressFamily # unix only
.AF_KEY: .AddressFamily # unix only
.AF_LLC: .AddressFamily # unix only
.AF_NETBEUI: .AddressFamily # unix only
.AF_NETLINK: .AddressFamily # unix only
.AF_NETROM: .AddressFamily
.AF_PACKET: .AddressFamily # unix only
.AF_PPPOX: .AddressFamily # unix only
.AF_QIPCRTR: .AddressFamily # unix only
.AF_RDS: .AddressFamily # unix only
.AF_ROSE: .AddressFamily
.AF_ROUTE: .AddressFamily # unix only
.AF_SECURITY: .AddressFamily # unix only
.AF_SNA: .AddressFamily
.AF_TIPC: .AddressFamily # unix only
.AF_UNIX: .AddressFamily # unix only
.AF_UNSPEC: .AddressFamily
.AF_VSOCK: .AddressFamily # unix only
.AF_WANPIPE: .AddressFamily # unix only
.AF_X25: .AddressFamily
.SO_ACCEPTCONN: Nat
.SO_BINDTODEVICE: Nat
.SO_BROADCAST: Nat
.SO_DEBUG: Nat
.SO_DOMAIN: Nat
.SO_DONTROUTE: Nat
.SO_ERROR: Nat
.SO_INCOMING_CPU: Nat
.SO_J1939_ERRQUEUE: Nat
.SO_J1939_FILTER: Nat
.SO_J1939_PROMISC: Nat
.SO_J1939_SEND_PRIO: Nat
.SO_KEEPALIVE: Nat
.SO_LINGER: Nat
.SO_MARK: Nat
.SO_OOBINLINE: Nat
.SO_PASSCRED: Nat
.SO_PASSSEC: Nat
.SO_PEERCRED: Nat
.SO_PEERSEC: Nat
.SO_PRIORITY: Nat
.SO_PROTOCOL: Nat
.SO_RCVBUF: Nat
.SO_RCVLOWAT: Nat
.SO_RCVTIMEO: Nat
.SO_REUSEADDR: Nat
.SO_REUSEPORT: Nat
.SO_SNDBUF: Nat
.SO_SNDLOWAT: Nat
.SO_SNDTIMEO: Nat
.SO_TYPE: Nat
.SO_VM_SOCKETS_BUFFER_MAX_SIZE: Nat
.SO_VM_SOCKETS_BUFFER_MIN_SIZE: Nat
.SO_VM_SOCKETS_BUFFER_SIZE: Nat
.SOL_ALG: Nat
.SOL_CAN_BASE: Nat
.SOL_CAN_RAW: Nat
.SOL_IP: Nat
.SOL_RDS: Nat
.SOL_SOCKET: Nat
.SOL_TCP: Nat
.SOL_TIPC: Nat
.SOL_UDP: Nat
.Socket!: ClassType .Socket!: ClassType
.Socket!.new: (family := Int, type := Int, proto := Int, fileno: Int or NoneType := NoneType) -> .Socket! .Socket!.new: (family := Int, type := Int, proto := Int, fileno: Int or NoneType := NoneType) -> .Socket!

View file

@ -6,6 +6,16 @@ io = pyimport "io"
.copyright: Str .copyright: Str
.executable: Str .executable: Str
.path: Array!(Str, _) .path: Array!(Str, _)
'''
* AIX -> 'aix'
* FreeBSD -> 'freebsd'
* Emscripten -> 'emscripten'
* Linux -> 'linux'
* WASI -> 'wasi'
* Windows -> 'win32'
* Windows/Cygwin -> 'cygwin'
* macOS -> 'darwin'
'''
.platform: Str .platform: Str
.prefix: Str .prefix: Str
.ps1: Str! .ps1: Str!

View file

@ -213,6 +213,7 @@ fn find_available_port() -> u16 {
.is_ok() .is_ok()
.then_some(DEFAULT_PORT) .then_some(DEFAULT_PORT)
.unwrap_or_else(|| { .unwrap_or_else(|| {
// localhost:0 will bind to a free port
let socket = SocketAddrV4::new(Ipv4Addr::LOCALHOST, 0); let socket = SocketAddrV4::new(Ipv4Addr::LOCALHOST, 0);
TcpListener::bind(socket) TcpListener::bind(socket)
.and_then(|listener| listener.local_addr()) .and_then(|listener| listener.local_addr())

View file

@ -6,6 +6,8 @@ import importlib as __importlib
import io as __io import io as __io
__server_socket = __socket.socket() __server_socket = __socket.socket()
if __sys.platform == 'linux':
__server_socket.setsockopt(__socket.SOL_SOCKET, __socket.SO_REUSEADDR, 1)
# DummyVM will replace this __PORT__ with free port # DummyVM will replace this __PORT__ with free port
__server_socket.bind(('127.0.0.1', __PORT__)) __server_socket.bind(('127.0.0.1', __PORT__))
__server_socket.listen(1) __server_socket.listen(1)