Skip to content

Commit

Permalink
[Truffle] Add socket posix send
Browse files Browse the repository at this point in the history
  • Loading branch information
Brandon Fish committed Oct 4, 2016
1 parent 16e383d commit 56ae861
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
Expand Up @@ -688,6 +688,17 @@ public int getppid() {

}

@CoreMethod(names = "send", isModuleFunction = true, required = 4, lowerFixnum = {1, 3, 4}, unsafe = UnsafeGroup.IO)
public abstract static class SendNode extends CoreMethodArrayArgumentsNode {

@TruffleBoundary
@Specialization(guards = "isRubyPointer(buffer)")
public int send(int descriptor, DynamicObject buffer, int bytes, int flags) {
return nativeSockets().send(descriptor, Layouts.POINTER.getPointer(buffer), bytes, flags);
}

}

@CoreMethod(names = "symlink", isModuleFunction = true, required = 2, unsafe = UnsafeGroup.IO)
public abstract static class SymlinkNode extends CoreMethodArrayArgumentsNode {

Expand Down
Expand Up @@ -85,6 +85,11 @@ public int connect(int socket, Pointer address, int address_len) {
throw new UnsupportedOperationException();
}

@Override
public int send(int sockfd, Pointer buf, int len, int flags) {
throw new UnsupportedOperationException();
}

@Override
public int shutdown(int socket, int how) {
throw new UnsupportedOperationException();
Expand Down
Expand Up @@ -119,6 +119,11 @@ public interface Sockets {

int connect(int socket, Pointer address, int address_len);

/**
* int send(int sockfd, Pointer buf, int len, int flags);
*/
int send(int sockfd, Pointer buf, int len, int flags);

/**
* int shutdown(int sockfd, int how);
*/
Expand Down

1 comment on commit 56ae861

@bjfish
Copy link
Contributor

@bjfish bjfish commented on 56ae861 Oct 4, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested this with netcat: nc -l 4444

require "socket"
s = TCPSocket.new('127.0.0.1',4444)
s.send('hello\000', 0) 

Please sign in to comment.