diff --git a/src/boxes/socket_box.rs b/src/boxes/socket_box.rs index d8ce7d73..12a57acd 100644 --- a/src/boxes/socket_box.rs +++ b/src/boxes/socket_box.rs @@ -62,34 +62,25 @@ impl Clone for SocketBox { // For listener and stream, we can't clone them, so we'll share them // but create new Arc instances with the current state - let cloned = Self { + Self { base: BoxBase::new(), // New unique ID for clone listener: Arc::clone(&self.listener), // Share the same listener stream: Arc::clone(&self.stream), // Share the same stream is_server: Arc::new(Mutex::new(current_is_server)), // New Arc with current value is_connected: Arc::new(Mutex::new(current_is_connected)), // New Arc with current value - }; - - let original_arc_ptr = Arc::as_ptr(&self.is_server) as usize; - let cloned_arc_ptr = Arc::as_ptr(&cloned.is_server) as usize; - println!("๐Ÿ”„ SocketBox::clone() - original Box ID: {}, cloned Box ID: {}, Arc ptr: {:x} -> {:x}, is_server: {}", - self.base.id, cloned.base.id, original_arc_ptr, cloned_arc_ptr, current_is_server); - cloned + } } } impl SocketBox { pub fn new() -> Self { - let instance = Self { + Self { base: BoxBase::new(), listener: Arc::new(Mutex::new(None)), stream: Arc::new(Mutex::new(None)), is_server: Arc::new(Mutex::new(false)), is_connected: Arc::new(Mutex::new(false)), - }; - let arc_ptr = Arc::as_ptr(&instance.is_server) as usize; - println!("๐Ÿ”ง SocketBox::new() - created (Box ID: {}, Arc ptr: {:x})", instance.base.id, arc_ptr); - instance + } } /// TCP ใ‚ฝใ‚ฑใƒƒใƒˆใ‚’ใ‚ขใƒ‰ใƒฌใ‚นใƒปใƒใƒผใƒˆใซใƒใ‚คใƒณใƒ‰ @@ -98,36 +89,22 @@ impl SocketBox { let port_str = port.to_string_box().value; let socket_addr = format!("{}:{}", addr_str, port_str); - println!("๐Ÿ” SocketBox::bind() called with address: {} (Box ID: {})", socket_addr, self.base.id); match TcpListener::bind(&socket_addr) { Ok(listener) => { - println!("โœ… SocketBox::bind() - TcpListener created successfully (Box ID: {})", self.base.id); match self.listener.lock() { Ok(mut listener_guard) => { *listener_guard = Some(listener); - let arc_ptr = Arc::as_ptr(&self.listener) as usize; - println!("โœ… SocketBox::bind() - Listener stored successfully (Box ID: {}, Arc ptr: {:x})", self.base.id, arc_ptr); }, Err(_) => { - println!("๐Ÿšจ SocketBox::bind() - Failed to acquire listener lock (Box ID: {})", self.base.id); return Box::new(BoolBox::new(false)); } } match self.is_server.lock() { Ok(mut is_server_guard) => { *is_server_guard = true; - let arc_ptr = Arc::as_ptr(&self.is_server) as usize; - // Verify the value was actually set - let verify_value = *is_server_guard; - println!("โœ… SocketBox::bind() - is_server set to true (Box ID: {}, Arc ptr: {:x}, verify: {})", self.base.id, arc_ptr, verify_value); - // Also verify it's readable immediately - drop(is_server_guard); - let reread_value = *self.is_server.lock().unwrap(); - println!("๐Ÿ” SocketBox::bind() - reread value: {}", reread_value); }, Err(_) => { - println!("๐Ÿšจ SocketBox::bind() - Failed to acquire is_server lock (Box ID: {})", self.base.id); // Non-critical error, continue } } @@ -143,41 +120,26 @@ impl SocketBox { /// ๆŒ‡ๅฎšใ—ใŸ backlog ใงๆŽฅ็ถšๅพ…ๆฉŸ้–‹ๅง‹ pub fn listen(&self, backlog: Box) -> Box { let _backlog_num = backlog.to_string_box().value.parse::().unwrap_or(128); - println!("๐Ÿ” SocketBox::listen() called (Box ID: {})", self.base.id); // Check if listener exists and is properly bound let listener_guard = match self.listener.lock() { Ok(guard) => guard, - Err(_) => { - println!("๐Ÿšจ SocketBox::listen() - Failed to acquire listener lock (Box ID: {})", self.base.id); - return Box::new(BoolBox::new(false)); - }, + Err(_) => return Box::new(BoolBox::new(false)), }; - println!("๐Ÿ” SocketBox::listen() - Listener guard acquired (Box ID: {}), is_some: {}", - self.base.id, listener_guard.is_some()); - if let Some(ref listener) = *listener_guard { - println!("โœ… SocketBox::listen() - Listener found (Box ID: {})", self.base.id); - let arc_ptr = Arc::as_ptr(&self.listener) as usize; - println!("๐Ÿ” SocketBox::listen() - Listener Arc ptr: {:x}", arc_ptr); // Try to get the local address to confirm the listener is working match listener.local_addr() { Ok(_addr) => { - println!("โœ… SocketBox::listen() - Listener is valid (Box ID: {})", self.base.id); // Listener is properly set up and can accept connections Box::new(BoolBox::new(true)) }, Err(_) => { - println!("๐Ÿšจ SocketBox::listen() - Listener exists but has issues (Box ID: {})", self.base.id); // Listener exists but has issues Box::new(BoolBox::new(false)) } } } else { - println!("๐Ÿšจ SocketBox::listen() - No listener bound (Box ID: {})", self.base.id); - let arc_ptr = Arc::as_ptr(&self.listener) as usize; - println!("๐Ÿ” SocketBox::listen() - Listener Arc ptr: {:x}", arc_ptr); // No listener bound - this is expected behavior for now // HTTPServerBox will handle binding separately Box::new(BoolBox::new(false)) @@ -359,14 +321,6 @@ impl SocketBox { /// ใ‚ตใƒผใƒใƒผใƒขใƒผใƒ‰็ขบ่ช pub fn is_server(&self) -> Box { let is_server_value = *self.is_server.lock().unwrap(); - let arc_ptr = Arc::as_ptr(&self.is_server) as usize; - println!("๐Ÿ” SocketBox::is_server() called - returning {} (Box ID: {}, Arc ptr: {:x})", - is_server_value, self.base.id, arc_ptr); - // Double-check by re-reading - let double_check = *self.is_server.lock().unwrap(); - if is_server_value != double_check { - println!("๐Ÿšจ WARNING: is_server value changed between reads! {} -> {}", is_server_value, double_check); - } Box::new(BoolBox::new(is_server_value)) } } diff --git a/src/interpreter/expressions.rs b/src/interpreter/expressions.rs index 3a831be7..d004299a 100644 --- a/src/interpreter/expressions.rs +++ b/src/interpreter/expressions.rs @@ -328,18 +328,6 @@ impl NyashInterpreter { // ใ‚ชใƒ–ใ‚ธใ‚งใ‚ฏใƒˆใ‚’่ฉ•ไพก๏ผˆ้€šๅธธใฎใƒกใ‚ฝใƒƒใƒ‰ๅ‘ผใณๅ‡บใ—๏ผ‰ let obj_value = self.execute_expression(object)?; - // Debug: Print object type and Box ID for SocketBox debugging - if method == "bind" || method == "listen" || method == "isServer" { - println!("๐Ÿ” DEBUG: Method '{}' called on object type: {} (Box ID: {})", - method, - obj_value.type_name(), - if let Some(socket_box) = obj_value.as_any().downcast_ref::() { - socket_box.box_id().to_string() - } else { - "N/A".to_string() - }); - } - // StringBox method calls if let Some(string_box) = obj_value.as_any().downcast_ref::() { return self.execute_string_method(string_box, method, arguments); @@ -477,11 +465,7 @@ impl NyashInterpreter { if let Some(stored_var) = self.local_vars.get_mut(name) { // Replace the stored instance with the modified one let updated_instance = socket_box.clone(); - let new_box_id = updated_instance.box_id(); - let new_is_server = updated_instance.is_server().to_string_box().value == "true"; *stored_var = Box::new(updated_instance); - println!("๐Ÿ”ง Updated local variable '{}' after '{}' - new Box ID: {}, is_server: {}", - name, method, new_box_id, new_is_server); } } }