Sha256: f43e1bb316571a508d8746f44374db31f69411f5182dd19eb0daf787e82e51ba

Contents?: true

Size: 1.03 KB

Versions: 12

Compression:

Stored size: 1.03 KB

Contents

require 'socket'

class IO
	def write_nonblock(data, exception: true)
		ensure_open_and_writable

		data = String data
		return 0 if data.empty?

		@ibuffer.unseek!(self) unless @sync

		self.nonblock = true

		begin
			Truffle::POSIX.write_string_nonblock(self, data)
		rescue Errno::EAGAIN
			if exception
				raise EAGAINWaitWritable
			else
				return :wait_writable
			end
		end
	end
end

class IO::BidirectionalPipe
	def write_nonblock(*args, **options)
		@write.write_nonblock(*args, **options)
	end
end

class Socket
	def connect_nonblock(sockaddr, exception: true)
		fcntl(Fcntl::F_SETFL, Fcntl::O_NONBLOCK)

		if sockaddr.is_a?(Addrinfo)
			sockaddr = sockaddr.to_sockaddr
		end

		status = Truffle::Socket::Foreign.connect(descriptor, sockaddr)

		# There should be a better way to do this than raising an exception!?
		if Errno.errno == Errno::EISCONN::Errno
			raise Errno::EISCONN
		end

		if status < 0
			if exception
				Truffle::Socket::Error.write_nonblock('connect(2)')
			else
				:wait_writable
			end
		else
			0
		end
	end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
async-io-1.23.1 spec/truffle.rb
async-io-1.23.0 spec/truffle.rb
async-io-1.22.0 spec/truffle.rb
async-io-1.21.0 spec/truffle.rb
async-io-1.20.0 spec/truffle.rb
async-io-1.18.5 spec/truffle.rb
async-io-1.18.4 spec/truffle.rb
async-io-1.18.3 spec/truffle.rb
async-io-1.18.2 spec/truffle.rb
async-io-1.18.1 spec/truffle.rb
async-io-1.17.2 spec/truffle.rb
async-io-1.17.1 spec/truffle.rb