@gjsify/net 0.22.0 → 0.23.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/esm/server.js CHANGED
@@ -1 +1 @@
1
- import"./_virtual/_rolldown/runtime.js";import{Socket as e}from"./socket.js";import t from"@girs/gio-2.0";import{createNodeError as n,deferEmit as r,ensureMainLoop as i}from"@gjsify/utils";import{EventEmitter as a}from"node:events";const o=new Set;var Server=class extends a{listening=!1;maxConnections;allowHalfOpen;_service=null;_connections=new Set;_address=null;constructor(e,t){super(),typeof e==`function`?(t=e,this.allowHalfOpen=!1):this.allowHalfOpen=e?.allowHalfOpen??!1,t&&this.on(`connection`,t)}listen(...e){let a=0,s=`0.0.0.0`,c=511,l;if(typeof e[0]==`object`&&e[0]!==null&&!Array.isArray(e[0])){let t=e[0];a=t.port??0,s=t.host??`0.0.0.0`,c=t.backlog??511,l=e[1]}else{typeof e[0]==`number`&&(a=e[0]);for(let t=1;t<e.length;t++)typeof e[t]==`string`?s=e[t]:typeof e[t]==`number`?c=e[t]:typeof e[t]==`function`&&(l=e[t])}l&&this.once(`listening`,l);try{this._service=new t.SocketService,this._service.set_backlog(c);let e;a===0?e=this._service.add_any_inet_port(null):(this._service.add_inet_port(a,null),e=a),this._service.connect(`incoming`,(e,t)=>(this._handleConnection(t),!0)),this._service.start(),i(),this.listening=!0,o.add(this);let n=s.includes(`:`)?`IPv6`:`IPv4`;this._address={port:e,family:n,address:s},r(this,`listening`)}catch(e){let t=n(e,`listen`,{address:s,port:a});r(this,`error`,t)}return this}_handleConnection(t){if(this.maxConnections&&this._connections.size>=this.maxConnections){try{t.close(null)}catch{}return}let n=new e({allowHalfOpen:this.allowHalfOpen});n._setConnection(t),n._setupConnection({}),this._connections.add(n),n.on(`close`,()=>{this._connections.delete(n)}),this.emit(`connection`,n)}address(){return this._address}close(e){if(e&&this.once(`close`,e),!this._service||!this.listening)return setTimeout(()=>{let e=Error(`Server is not running`);e.code=`ERR_SERVER_NOT_RUNNING`,this.emit(`error`,e)},0),this;this._service.stop(),this._service.close(),this._service=null,this.listening=!1,o.delete(this);for(let e of this._connections)e.destroy();return this._connections.clear(),r(this,`close`),this}getConnections(e){e(null,this._connections.size)}ref(){return this}unref(){return this}};export{Server};
1
+ import"./_virtual/_rolldown/runtime.js";import{Socket as e}from"./socket.js";import t from"@girs/gio-2.0";import{EventEmitter as n}from"node:events";import{createNodeError as r,deferEmit as i,ensureMainLoop as a}from"@gjsify/utils/core";const o=new Set;var Server=class extends n{listening=!1;maxConnections;allowHalfOpen;_service=null;_connections=new Set;_address=null;constructor(e,t){super(),typeof e==`function`?(t=e,this.allowHalfOpen=!1):this.allowHalfOpen=e?.allowHalfOpen??!1,t&&this.on(`connection`,t)}listen(...e){let n=0,s=`0.0.0.0`,c=511,l;if(typeof e[0]==`object`&&e[0]!==null&&!Array.isArray(e[0])){let t=e[0];n=t.port??0,s=t.host??`0.0.0.0`,c=t.backlog??511,l=e[1]}else{typeof e[0]==`number`&&(n=e[0]);for(let t=1;t<e.length;t++)typeof e[t]==`string`?s=e[t]:typeof e[t]==`number`?c=e[t]:typeof e[t]==`function`&&(l=e[t])}l&&this.once(`listening`,l);try{this._service=new t.SocketService,this._service.set_backlog(c);let e;n===0?e=this._service.add_any_inet_port(null):(this._service.add_inet_port(n,null),e=n),this._service.connect(`incoming`,(e,t)=>(this._handleConnection(t),!0)),this._service.start(),a(),this.listening=!0,o.add(this);let r=s.includes(`:`)?`IPv6`:`IPv4`;this._address={port:e,family:r,address:s},i(this,`listening`)}catch(e){let t=r(e,`listen`,{address:s,port:n});i(this,`error`,t)}return this}_handleConnection(t){if(this.maxConnections&&this._connections.size>=this.maxConnections){try{t.close(null)}catch{}return}let n=new e({allowHalfOpen:this.allowHalfOpen});n._setConnection(t),n._setupConnection({}),this._connections.add(n),n.on(`close`,()=>{this._connections.delete(n)}),this.emit(`connection`,n)}address(){return this._address}close(e){if(e&&this.once(`close`,e),!this._service||!this.listening)return setTimeout(()=>{let e=Error(`Server is not running`);e.code=`ERR_SERVER_NOT_RUNNING`,this.emit(`error`,e)},0),this;this._service.stop(),this._service.close(),this._service=null,this.listening=!1,o.delete(this);for(let e of this._connections)e.destroy();return this._connections.clear(),i(this,`close`),this}getConnections(e){e(null,this._connections.size)}ref(){return this}unref(){return this}};export{Server};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gjsify/net",
3
- "version": "0.22.0",
3
+ "version": "0.23.0",
4
4
  "description": "Node.js net module for Gjs",
5
5
  "type": "module",
6
6
  "module": "lib/esm/index.js",
@@ -37,18 +37,18 @@
37
37
  "net"
38
38
  ],
39
39
  "devDependencies": {
40
- "@gjsify/cli": "^0.22.0",
41
- "@gjsify/unit": "^0.22.0",
40
+ "@gjsify/cli": "^0.23.0",
41
+ "@gjsify/unit": "^0.23.0",
42
42
  "@types/node": "^25.9.2",
43
43
  "typescript": "^6.0.3"
44
44
  },
45
45
  "dependencies": {
46
46
  "@girs/gio-2.0": "^4.1.0",
47
47
  "@girs/glib-2.0": "^4.1.0",
48
- "@gjsify/buffer": "^0.22.0",
49
- "@gjsify/events": "^0.22.0",
50
- "@gjsify/stream": "^0.22.0",
51
- "@gjsify/utils": "^0.22.0"
48
+ "@gjsify/buffer": "^0.23.0",
49
+ "@gjsify/events": "^0.23.0",
50
+ "@gjsify/stream": "^0.23.0",
51
+ "@gjsify/utils": "^0.23.0"
52
52
  },
53
53
  "gjsify": {
54
54
  "runtimes": {