| 
									
										
										
										
											2024-09-27 02:50:37 +01:00
										 |  |  | # typed: strict | 
					
						
							|  |  |  | # frozen_string_literal: true | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | require "socket" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | module OS | 
					
						
							|  |  |  |   module Mac | 
					
						
							|  |  |  |     # Wrapper around UNIXSocket to allow > 104 characters on macOS. | 
					
						
							|  |  |  |     module UNIXSocketExt | 
					
						
							| 
									
										
										
										
											2025-06-21 21:40:57 -04:00
										 |  |  |       module ClassMethods | 
					
						
							|  |  |  |         extend T::Helpers | 
					
						
							| 
									
										
										
										
											2024-09-27 02:50:37 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-06-21 21:40:57 -04:00
										 |  |  |         requires_ancestor { Kernel } | 
					
						
							| 
									
										
										
										
											2024-09-27 02:50:37 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-06-21 21:40:57 -04:00
										 |  |  |         sig { params(path: String).returns(String) } | 
					
						
							|  |  |  |         def sockaddr_un(path) | 
					
						
							|  |  |  |           if path.bytesize > 252 # largest size that can fit into a single-byte length | 
					
						
							|  |  |  |             raise ArgumentError, "too long unix socket path (#{path.bytesize} bytes given but 252 bytes max)" | 
					
						
							|  |  |  |           end | 
					
						
							| 
									
										
										
										
											2024-09-27 02:50:37 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-06-21 21:40:57 -04:00
										 |  |  |           [ | 
					
						
							|  |  |  |             path.bytesize + 3, # = length (1 byte) + family (1 byte) + path (variable) + null terminator (1 byte) | 
					
						
							|  |  |  |             1, # AF_UNIX | 
					
						
							|  |  |  |             path, | 
					
						
							|  |  |  |           ].pack("CCZ*") | 
					
						
							|  |  |  |         end | 
					
						
							| 
									
										
										
										
											2024-09-27 02:50:37 +01:00
										 |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-06-21 21:40:57 -04:00
										 |  |  | Utils::UNIXSocketExt.singleton_class.prepend(OS::Mac::UNIXSocketExt::ClassMethods) |