Skip to content

Commit 510f0e0

Browse files
committed
stub get,setsockopt
1 parent ab84d01 commit 510f0e0

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/socket/PSocket.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,12 @@
4545
import java.nio.channels.Channel;
4646
import java.nio.channels.ServerSocketChannel;
4747
import java.nio.channels.SocketChannel;
48+
import java.util.HashMap;
4849

50+
import com.oracle.graal.python.builtins.objects.PNone;
4951
import com.oracle.graal.python.builtins.objects.object.PythonBuiltinObject;
5052
import com.oracle.graal.python.builtins.objects.type.LazyPythonClass;
53+
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
5154

5255
public class PSocket extends PythonBuiltinObject implements Channel {
5356
public static final int AF_UNSPEC = 0;
@@ -98,6 +101,8 @@ public class PSocket extends PythonBuiltinObject implements Channel {
98101
private ServerSocketChannel serverSocket;
99102
private boolean blocking;
100103

104+
private HashMap<Object, Object> options;
105+
101106
public PSocket(LazyPythonClass cls, int family, int type, int proto) {
102107
super(cls);
103108
this.family = family;
@@ -184,4 +189,20 @@ public void close() throws IOException {
184189
getSocket().close();
185190
}
186191
}
192+
193+
@TruffleBoundary
194+
public void setSockOpt(Object option, Object value) {
195+
if (options == null) {
196+
options = new HashMap<>();
197+
}
198+
options.put(option, value);
199+
}
200+
201+
@TruffleBoundary
202+
public Object getSockOpt(Object option) {
203+
if (options != null) {
204+
return options.getOrDefault(option, PNone.NONE);
205+
}
206+
return PNone.NONE;
207+
}
187208
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/socket/SocketBuiltins.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -601,4 +601,23 @@ Object setSockOpt(PSocket socket, Object level, Object optname, Object value, Ob
601601
}
602602
}
603603

604+
@Builtin(name = "setsockopt", minNumOfPositionalArgs = 4)
605+
@GenerateNodeFactory
606+
abstract static class SetSockOptionNode extends PythonBuiltinNode {
607+
@Specialization
608+
Object setSockOpt(PSocket socket, @SuppressWarnings("unused") Object level, Object option, Object value) {
609+
// TODO: Implement these
610+
socket.setSockOpt(option, value);
611+
return PNone.NONE;
612+
}
613+
}
614+
615+
@Builtin(name = "getsockopt", minNumOfPositionalArgs = 3)
616+
@GenerateNodeFactory
617+
abstract static class GetSockOptionNode extends PythonBuiltinNode {
618+
@Specialization
619+
Object setSockOpt(PSocket socket, @SuppressWarnings("unused") Object level, Object option) {
620+
return socket.getSockOpt(option);
621+
}
622+
}
604623
}

0 commit comments

Comments
 (0)