Skip to content

Commit ae23d09

Browse files
committed
chore: add CONTRIBUTING.md
1 parent bf8a025 commit ae23d09

File tree

8 files changed

+254
-205
lines changed

8 files changed

+254
-205
lines changed

CONTRIBUTING.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# CONTRIBUTING
2+
We love your input! We want to make contributing to this project as easy and transparent as possible, whether it's:
3+
4+
- Reporting a bug
5+
- Discussing the current state of the code
6+
- Submitting a fix
7+
- Proposing new features
8+
- Becoming a maintainer
9+
10+
## We Develop with Github
11+
We use github to host code, to track issues and feature requests, as well as accept pull requests.
12+
13+
## We Use [Github Flow](https://guides.github.com/introduction/flow/index.html), So All Code Changes Happen Through Pull Requests
14+
Pull requests are the best way to propose changes to the codebase (we use [Github Flow](https://guides.github.com/introduction/flow/index.html)). We actively welcome your pull requests:
15+
16+
1. Fork the repo and create your branch from `master`.
17+
2. If you've added code that should be tested, add tests.
18+
3. If you've changed APIs, update the documentation.
19+
4. Ensure the test suite passes.
20+
5. Make sure your code lints.
21+
6. Issue that pull request!
22+
23+
## Any contributions you make will be under the MIT Software License
24+
In short, when you submit code changes, your submissions are understood to be under the same [MIT License](http://choosealicense.com/licenses/mit/) that covers the project. Feel free to contact the maintainers if that's a concern.
25+
26+
## Report bugs using Github's [issues](https://github.com/briandk/transcriptase-atom/issues)
27+
We use GitHub issues to track public bugs. Report a bug by [opening a new issue](); it's that easy!
28+
29+
## Write bug reports with detail, background, and sample code
30+
[This is an example](http://stackoverflow.com/q/12488905/180626) of a bug report I wrote, and I think it's not a bad model. Here's [another example from Craig Hockenberry](http://www.openradar.me/11905408), an app developer whom I greatly respect.
31+
32+
**Great Bug Reports** tend to have:
33+
34+
- A quick summary and/or background
35+
- Steps to reproduce
36+
- Be specific!
37+
- Give sample code if you can. [My stackoverflow question](http://stackoverflow.com/q/12488905/180626) includes sample code that *anyone* with a base R setup can run to reproduce what I was seeing
38+
- What you expected would happen
39+
- What actually happens
40+
- Notes (possibly including why you think this might be happening, or stuff you tried that didn't work)
41+
42+
People *love* thorough bug reports. I'm not even kidding.
43+
44+
## License
45+
By contributing, you agree that your contributions will be licensed under its MIT License.

README.md

Lines changed: 68 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# nix-socket
22

33
`nix-socket` allows you to use some nonblocking sockets that are not supported by Node.js native modules, including:
4+
45
- Using `SO_REUSEPORT` enabled TCP [net.Server](https://nodejs.org/dist/latest-v16.x/docs/api/net.html#class-netserver)
56
- unix seqpacket(`SOCK_SEQPACKET`) sockets
67
- unix datagram(`SOCK_DGRAM`) sockets
@@ -26,40 +27,43 @@ Note that `SO_REUSEPORT` might behave much differently across operating systems.
2627
### Example
2728

2829
```js
29-
const { createReuseportFd } = require('nix-socket')
30-
const { Server, Socket } = require('net')
30+
const { createReuseportFd } = require('nix-socket');
31+
const { Server, Socket } = require('net');
3132

32-
const port = 8080
33-
const host = '0.0.0.0'
33+
const port = 8080;
34+
const host = '0.0.0.0';
3435

3536
// create multple servers listening to a same host, port.
3637
for (let i = 0; i < 2; i += 1) {
37-
const fd = createReuseportFd(port, host)
38+
const fd = createReuseportFd(port, host);
3839
const server = new Server((socket) => {
3940
socket.on('data', (buf) => {
40-
console.log(`server ${i} received:`, buf)
41+
console.log(`server ${i} received:`, buf);
4142
// echo
42-
socket.write(buf)
43-
})
44-
})
45-
46-
server.listen({
47-
fd,
48-
}, () => {
49-
console.log(`server ${i} is listening on ${port}`)
50-
})
43+
socket.write(buf);
44+
});
45+
});
46+
47+
server.listen(
48+
{
49+
fd,
50+
},
51+
() => {
52+
console.log(`server ${i} is listening on ${port}`);
53+
}
54+
);
5155
}
5256

5357
setInterval(() => {
54-
const client = new Socket()
58+
const client = new Socket();
5559
client.on('data', (buf) => {
56-
console.log('client received:', buf)
57-
client.destroy()
58-
})
60+
console.log('client received:', buf);
61+
client.destroy();
62+
});
5963
client.connect(port, host, () => {
60-
client.write(Buffer.from('hello'))
61-
})
62-
}, 1000)
64+
client.write(Buffer.from('hello'));
65+
});
66+
}, 1000);
6367
```
6468

6569
## Seqpacket Sockets
@@ -71,80 +75,80 @@ Note that `SOCK_SEQPACKET` sockets don't work on MacOS.
7175
### Example
7276

7377
```js
74-
const { SeqpacketServer, SeqpacketSocket } = require('nix-socket')
75-
const os = require('os')
76-
const path = require('path')
77-
const fs = require('fs')
78-
79-
const bindPath = path.resolve(os.tmpdir(), './my_seqpacket.sock')
78+
const { SeqpacketServer, SeqpacketSocket } = require('nix-socket');
79+
const os = require('os');
80+
const path = require('path');
81+
const fs = require('fs');
8082

81-
try { fs.unlinkSync(bindPath) } catch (e) {}
83+
const bindPath = path.resolve(os.tmpdir(), './my_seqpacket.sock');
8284

83-
const server = new SeqpacketServer()
84-
server.listen(bindPath)
85-
server.on('connection', socket => {
86-
socket.on('data', buf => {
87-
console.log('received', buf.toString())
88-
})
85+
try {
86+
fs.unlinkSync(bindPath);
87+
} catch (e) {}
88+
89+
const server = new SeqpacketServer();
90+
server.listen(bindPath);
91+
server.on('connection', (socket) => {
92+
socket.on('data', (buf) => {
93+
console.log('received', buf.toString());
94+
});
8995
});
9096

91-
const client = new SeqpacketSocket()
97+
const client = new SeqpacketSocket();
9298
client.connect(bindPath, () => {
93-
const data = [
94-
'hello, ',
95-
'w',
96-
'o',
97-
'r',
98-
'l',
99-
'd'
100-
]
99+
const data = ['hello, ', 'w', 'o', 'r', 'l', 'd'];
101100

102101
for (const str of data) {
103-
client.write(Buffer.from(str))
102+
client.write(Buffer.from(str));
104103
}
105-
client.end()
106-
})
104+
client.end();
105+
});
107106
```
108107

109108
## Dgram Sockets
110109

111110
### Example
112111

113112
```js
114-
const { DgramSocket } = require('nix-socket')
115-
const os = require('os')
116-
const path = require('path')
117-
const fs = require('fs')
113+
const { DgramSocket } = require('nix-socket');
114+
const os = require('os');
115+
const path = require('path');
116+
const fs = require('fs');
118117

119-
const path1 = path.resolve(os.tmpdir(), './my_dgram_1.sock')
120-
const path2 = path.resolve(os.tmpdir(), './my_dgram_2.sock')
118+
const path1 = path.resolve(os.tmpdir(), './my_dgram_1.sock');
119+
const path2 = path.resolve(os.tmpdir(), './my_dgram_2.sock');
121120

122121
try {
123122
fs.unlinkSync(path1);
124123
fs.unlinkSync(path2);
125124
} catch (err) {}
126125

127-
const socket1 = new DgramSocket()
128-
const socket2 = new DgramSocket()
126+
const socket1 = new DgramSocket();
127+
const socket2 = new DgramSocket();
129128

130-
socket1.bind(path1)
131-
socket2.bind(path2)
129+
socket1.bind(path1);
130+
socket2.bind(path2);
132131

133132
socket2.on('data', (data, remoteAddr) => {
134-
console.log(`socket2 received: ${data.toString()}`)
133+
console.log(`socket2 received: ${data.toString()}`);
135134
// echo
136135
socket2.sendTo(data, 0, data.length, remoteAddr);
137-
})
136+
});
138137

139138
socket1.on('data', (data) => {
140-
console.log(`socket1 received: ${data.toString()}`)
141-
})
139+
console.log(`socket1 received: ${data.toString()}`);
140+
});
142141

143142
setInterval(() => {
144-
const buf = Buffer.from('hello')
145-
socket1.sendTo(buf, 0, buf.length, path2)
146-
}, 1000)
143+
const buf = Buffer.from('hello');
144+
socket1.sendTo(buf, 0, buf.length, path2);
145+
}, 1000);
147146
```
148147

148+
## CONTRIBUTING
149+
150+
[CONTRIBUTING.md](./CONTRIBUTING.md)
151+
149152
## LICENSE
153+
150154
MIT

0 commit comments

Comments
 (0)