public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
From: "Zac Medico" <zmedico@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/portage:2.1.9 commit in: bin/
Date: Fri, 18 Mar 2011 21:12:28 +0000 (UTC)	[thread overview]
Message-ID: <768958c9d1504f72d2f252c1793a5bc48a2a4a85.zmedico@gentoo> (raw)

commit:     768958c9d1504f72d2f252c1793a5bc48a2a4a85
Author:     Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Thu Mar 17 21:12:13 2011 +0000
Commit:     Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Fri Mar 18 19:50:14 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=768958c9

ebuild-ipc: use non-blocking read

This makes it possible for the daemon to send a reply without blocking,
thereby improving performance and also making it possible for the
daemon to do a non-blocking write without a race condition.

This reverts part of commit 81fc303212b8379219cf5d463c8717359b972dba,
which probably didn't help portability anyway. Now, ebuild-ipc is using
non-blocking read with os.read and EAGAIN handling, just like
EbuildIpcDaemon since commit 7e5b81da12dd7bd59f6620840dc0d824e3f4d69a
(known compatible with FreeBSD).

---
 bin/ebuild-ipc.py |   54 ++++++++++++++++++++++++++++++++++++++++------------
 1 files changed, 41 insertions(+), 13 deletions(-)

diff --git a/bin/ebuild-ipc.py b/bin/ebuild-ipc.py
index d8e7e55..cb77171 100755
--- a/bin/ebuild-ipc.py
+++ b/bin/ebuild-ipc.py
@@ -134,23 +134,43 @@ class EbuildIpc(object):
 
 		return os.WEXITSTATUS(wait_retval[1])
 
-	def _receive_reply(self):
+	def _receive_reply(self, input_fd):
 
-		# File streams are in unbuffered mode since we do atomic
-		# read and write of whole pickles.
-		input_file = open(self.ipc_out_fifo, 'rb', 0)
-
-		# For maximum portability, use a single atomic read.
+		# Timeouts are handled by the parent process, so just
+		# block until input is available. For maximum portability,
+		# use a single atomic read.
 		buf = None
-		try:
-			buf = input_file.read(self._BUFSIZE)
-		except IOError as e:
-			if not buf:
+		while True:
+			try:
+				events = select.select([input_fd], [], [])
+			except select.error as e:
 				portage.util.writemsg_level(
-					"ebuild-ipc: %s\n" % (e,),
+					"ebuild-ipc: %s: %s\n" % \
+					(portage.localization._('during select for read'), e),
 					level=logging.ERROR, noiselevel=-1)
+				continue
 
-		input_file.close()
+			if events[0]:
+				# For maximum portability, use os.read() here since
+				# array.fromfile() and file.read() are both known to
+				# erroneously return an empty string from this
+				# non-blocking fifo stream on FreeBSD (bug #337465).
+				try:
+					buf = os.read(input_fd, self._BUFSIZE)
+				except OSError as e:
+					if e.errno != errno.EAGAIN:
+						portage.util.writemsg_level(
+							"ebuild-ipc: %s: %s\n" % \
+							(portage.localization._('read error'), e),
+							level=logging.ERROR, noiselevel=-1)
+						break
+					# Assume that another event will be generated
+					# if there's any relevant data.
+					continue
+
+				# Only one (atomic) read should be necessary.
+				if buf:
+					break
 
 		retval = 2
 
@@ -192,6 +212,13 @@ class EbuildIpc(object):
 			self._no_daemon_msg()
 			return 2
 
+		# Open the input fifo before the output fifo, in order to make it
+		# possible for the daemon to send a reply without blocking. This
+		# improves performance, and also makes it possible for the daemon
+		# to do a non-blocking write without a race condition.
+		input_fd = os.open(self.ipc_out_fifo,
+			os.O_RDONLY|os.O_NONBLOCK)
+
 		# Use forks so that the child process can handle blocking IO
 		# un-interrupted, while the parent handles all timeout
 		# considerations. This helps to avoid possible race conditions
@@ -231,12 +258,13 @@ class EbuildIpc(object):
 
 		if pid == 0:
 			os.close(pr)
-			retval = self._receive_reply()
+			retval = self._receive_reply(input_fd)
 			os._exit(retval)
 
 		os.close(pw)
 		retval = self._wait(pid, pr, portage.localization._('during read'))
 		os.close(pr)
+		os.close(input_fd)
 		return retval
 
 def ebuild_ipc_main(args):



             reply	other threads:[~2011-03-18 21:12 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-03-18 21:12 Zac Medico [this message]
  -- strict thread matches above, loose matches on Subject: below --
2011-05-26  6:18 [gentoo-commits] proj/portage:2.1.9 commit in: bin/ Zac Medico
2011-05-26  6:18 Zac Medico
2011-05-05  6:48 Zac Medico
2011-05-04 20:03 Zac Medico
2011-05-04 20:03 Zac Medico
2011-05-04 20:03 Zac Medico
2011-05-04 20:03 Zac Medico
2011-05-04 20:03 Zac Medico
2011-05-04 20:03 Zac Medico
2011-04-14  1:57 Zac Medico
2011-04-13  7:52 Zac Medico
2011-04-13  7:52 Zac Medico
2011-04-13  7:52 Zac Medico
2011-04-13  7:52 Zac Medico
2011-03-27 20:03 Zac Medico
2011-03-26 19:31 Zac Medico
2011-03-26 19:31 Zac Medico
2011-03-18 21:12 Zac Medico
2011-03-14 16:24 Zac Medico
2011-03-02  0:56 Zac Medico
2011-03-01 20:55 Zac Medico
2011-02-22  3:14 Zac Medico
2011-02-20  0:04 Zac Medico
2011-02-20  0:04 Zac Medico
2011-02-14  4:31 Zac Medico
2011-02-14  4:31 Zac Medico
2011-02-07  0:29 Zac Medico

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=768958c9d1504f72d2f252c1793a5bc48a2a4a85.zmedico@gentoo \
    --to=zmedico@gentoo.org \
    --cc=gentoo-commits@lists.gentoo.org \
    --cc=gentoo-dev@lists.gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox