Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Low-level backend support for sockets

  • Loading branch information...
commit ec0eab354f518596d8b32e13380f129e3c550ecc 1 parent 51face1
@sorear sorear authored
Showing with 27 additions and 0 deletions.
  1. +26 −0 lib/Builtins.cs
  2. +1 −0  lib/CodeGen.cs
View
26 lib/Builtins.cs
@@ -7,6 +7,7 @@
using System.Runtime.CompilerServices;
using System.Threading;
using System.Text;
+using System.Net.Sockets;
namespace Niecza {
// IForeignInterpreter is used for runtime loading of the Perl 5
@@ -2934,4 +2935,29 @@ public class Blackhole : Variable {
public static int blob_len(byte[] inp) {
return inp.Length;
}
+
+ public static Socket socket_new(int family, int type, int proto) {
+ return new Socket( (AddressFamily)family, (SocketType)type,
+ (ProtocolType)proto );
+ }
+
+ public static byte[] socket_read(Socket from, int ct) {
+ byte[] buf = new byte[ct];
+ int rct = from.Receive(buf);
+ Array.Resize(ref buf, rct);
+ return buf;
+ }
+
+ public static void socket_write(Socket sock, byte[] data) {
+ sock.Send(data);
+ }
+
+ public static void socket_close(Socket sock) {
+ sock.Shutdown( SocketShutdown.Both ); // XXX perhaps should be separate
+ sock.Close();
+ }
+
+ public static void socket_connect(Socket sock, string host, int port) {
+ sock.Connect(host, port);
+ }
}
View
1  lib/CodeGen.cs
@@ -2450,6 +2450,7 @@ class NamProcessor {
namtypes["treader"] = typeof(TextReader);
namtypes["twriter"] = typeof(TextWriter);
namtypes["blob"] = typeof(byte[]);
+ namtypes["socket"] = typeof(System.Net.Sockets.Socket);
handlers = new Dictionary<string, Func<NamProcessor,object[],CpsOp>>();
thandlers = new Dictionary<string, Func<CpsOp[], CpsOp>>();
Please sign in to comment.
Something went wrong with that request. Please try again.