[Pkg-javascript-commits] [node-ain2] 90/102: adding concurrency patch by @cblage This patch reuses the local socket to send calls instead of opening a new one every time
Jonas Smedegaard
js at moszumanska.debian.org
Tue Apr 29 11:59:52 UTC 2014
This is an automated email from the git hooks/post-receive script.
js pushed a commit to branch master
in repository node-ain2.
commit 96a7f5ce711e9f0f082e38651e908b9111d07f5b
Author: Patrick Huesler <patrick.huesler at gmail.com>
Date: Fri Nov 30 20:00:42 2012 +0100
adding concurrency patch by @cblage
This patch reuses the local socket to send calls
instead of opening a new one every time
See his [pull request](https://github.com/phuesler/ain/pull/10)
---
index.js | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 66 insertions(+)
diff --git a/index.js b/index.js
index f28bf2f..b000de4 100644
--- a/index.js
+++ b/index.js
@@ -6,6 +6,72 @@ var DefaultHostname = require("os").hostname();
var DefaultAddress = "127.0.0.1";
var SingletonInstance = null;
+var socket
+var socketUsers = 0
+var releaseTimeout
+var socketErrorHandler = function (err) {
+
+ if (err) {
+
+ nodeConsole.error('socket error: ' + err)
+
+ } else {
+
+ nodeConsole.error('unknown socket error!')
+
+ }
+
+
+
+ if (socket !== undefined) {
+
+ socket.close()
+
+ socket = undefined
+
+ socketUsers = 0
+
+ }
+
+}
+var getSocket = function () {
+
+ if (undefined === socket) {
+
+ socket = dgram.createSocket('udp4')
+
+ socket.on('error', socketErrorHandler)
+
+ }
+
+ ++socketUsers
+
+ return socket
+
+}
+var releaseSocket = function () {
+
+ --socketUsers
+
+ if (0 == socketUsers && undefined === releaseTimeout) {
+
+ releaseTimeout = setTimeout(function () {
+
+ if (0 == socketUsers && socket !== undefined) {
+
+ socket.close()
+
+ socket = undefined
+
+ }
+
+ releaseTimeout = undefined
+
+ }, 1000)
+
+ }
+
+}
var Transport = {
UDP: function(message, severity) {
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-ain2.git
More information about the Pkg-javascript-commits
mailing list