Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix] setsockopt errno 22 #190

Closed
wants to merge 1 commit into from
Closed

Conversation

yyk808
Copy link

@yyk808 yyk808 commented Jul 4, 2024

fix #188 (comment)

seems like setsockopt() will regard buf.data() as (int*)? I'm not quite sure, however this commit will make the function return no error code.

Test

On the server side:

pipy -e 'pipy().listen(8000).connect('127.0.0.1:1234')'

On the client side:

pipy().task().onStart(new Message('Turn around')).connect('127.0.0.1:8000', {
	onState: (conn) => {
		if(conn.state === 'open') {
			console.info(conn.socket.setRawOption(1, 15, new Data([1])))
		}
	},
	bind: '127.0.0.1:1234'
})
.listen('127.0.0.1:1234').print()

The result we shall got:
图片

@yyk808 yyk808 changed the title [fix] setsocopt errno 22 [fix] setsockopt errno 22 Jul 4, 2024
@pajama-coder
Copy link
Collaborator

new Data(array) will always take the array as a byte array, so in the code where you made changes, buf.size() is always a size in bytes. When setsockopt() needs an int, which is 4 byte long, you should give it something like:

new Data([0, 0, 0, 0])

But that is endianness dependent. To use the current host's endianness, you can make use of the CStruct API like this:

var int32 = new CStruct({ v: 'int32' })
int32.encode({ v: 8 }) // returns new Data([8, 0, 0, 0]) on little endian systems

@yyk808
Copy link
Author

yyk808 commented Jul 13, 2024

Thank you for your patience on this topic. As this problem can be fixed on pjs side, I'll just close this pr.

@yyk808 yyk808 closed this Jul 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

bind override socket.setRawOption
2 participants