Esempio n. 1
0
 private static void ReceiveFrom(IntPtr info)
 {
     InternalReceive(info, true, (callmode, socket, data, buffer, ofs, count, flags, remoteep) =>
     {
         EndPoint endpoint = new IPEndPoint(IPAddress.Any, 0);
         int len           = 0;
         bool success      = false;
         if (callmode == 0)
         {
             success = SocketExtension.ReceiveForm(socket, buffer, 0, count, flags, ref endpoint, out len);
         }
         else if (callmode == 1)
         {
             if ((success = SocketExtension.ReceiveForm(socket, buffer, ofs, count, flags, ref endpoint, out len)))
             {
                 for (int i = ofs; i < len; i++)
                 {
                     data[i] = buffer[i];
                 }
             }
         }
         else
         {
             throw new NotSupportedException("callmode");
         }
         if (success)
         {
             ObjectAuxiliary.Fill(ObjectAuxiliary.ToObject(remoteep.VirtualMachine, endpoint), remoteep);
         }
         return(len);
     });
 }
Esempio n. 2
0
        private static void GetHostEntry(IntPtr info)
        {
            NSJSFunctionCallbackInfo arguments = NSJSFunctionCallbackInfo.From(info);
            string hostNameOrAddress           = arguments.Length > 0 ? (arguments[0] as NSJSString)?.Value : null;

            try
            {
                if (hostNameOrAddress == null)
                {
                    Throwable.ArgumentNullException(arguments.VirtualMachine);
                }
                else if (hostNameOrAddress.Length <= 0)
                {
                    Throwable.ArgumentException(arguments.VirtualMachine);
                }
                else
                {
                    IPHostEntry host = DNS.GetHostEntry(hostNameOrAddress);
                    arguments.SetReturnValue(ObjectAuxiliary.ToObject(arguments.VirtualMachine, host));
                }
            }
            catch (Exception e)
            {
                Throwable.Exception(arguments.VirtualMachine, e);
            }
        }
Esempio n. 3
0
        public static NSJSObject New(NSJSVirtualMachine machine, WebSocket websocket)
        {
            if (machine == null || websocket == null)
            {
                return(null);
            }
            object usertoken = websocket.UserToken;

            if (usertoken != null)
            {
                return(usertoken as NSJSObject);
            }
            NSJSObject objective = NSJSObject.New(machine);

            objective.Set("Open", m_OpenProc);
            objective.Set("Close", m_CloseProc);
            objective.Set("Dispose", m_CloseProc);
            objective.Set("Send", m_SendProc);
            objective.Set("Path", websocket.Path);

            objective.Set("Ttl", websocket.Ttl);
            objective.Set("Handle", websocket.Handle.ToInt32());
            objective.Set("LocalEndPoint", ObjectAuxiliary.ToObject(machine, websocket.LocalEndPoint));
            objective.Set("RemoteEndPoint", ObjectAuxiliary.ToObject(machine, websocket.RemoteEndPoint));

            objective.Set("OnMessage", NSJSValue.Null(machine));
            objective.Set("OnClose", NSJSValue.Null(machine));
            objective.Set("OnError", NSJSValue.Null(machine));
            objective.Set("OnOpen", NSJSValue.Null(machine));

            websocket.OnMessage += m_OnMessageProc;
            websocket.OnOpen    += m_OnOpenProc;
            websocket.OnError   += m_OnErrorProc;
            websocket.OnClose   += m_OnCloseProc;

            websocket.UserToken      = objective;
            objective.CrossThreading = true;

            objective.DefineProperty("NoDelay", m_NoDelayProc, m_NoDelayProc);
            objective.DefineProperty("Available", m_AvailableProc, (NSJSFunctionCallback)null);

            NSJSKeyValueCollection.Set(objective, websocket);
            return(objective);
        }
Esempio n. 4
0
        private static NSJSObject New(NSJSVirtualMachine machine, SOCKET socket)
        {
            if (machine == null || socket == null)
            {
                return(null);
            }
            NSJSObject o = NSJSObject.New(machine);

            o.Set("MSS", SocketExtension.MSS);
            o.Set("PPP", SocketExtension.PPP);
            o.Set("MTU", SocketExtension.MTU);
            o.Set("LocalEndPoint", ObjectAuxiliary.ToObject(machine, socket.LocalEndPoint));
            o.Set("RemoteEndPoint", ObjectAuxiliary.ToObject(machine, socket.RemoteEndPoint));
            o.Set("Send", m_SendProc);
            o.Set("Bind", m_BindProc);
            o.Set("Handle", socket.Handle.ToInt32());
            o.Set("Close", m_CloseProc);
            o.Set("Dispose", m_CloseProc);
            o.Set("Connect", m_ConnectProc);
            o.Set("Receive", m_ReceiveProc);
            o.Set("Accept", m_AcceptProc);
            o.Set("Connected", m_ConnectedProc);
            o.Set("ConnectAsync", m_ConnectAsyncProc);
            o.Set("AcceptAsync", m_AcceptAsyncProc);
            o.Set("SendAsync", m_SendAsyncProc);
            o.Set("ReceiveAsync", m_ReceiveAsyncProc);
            o.Set("SendTo", m_SendToProc);
            o.Set("SendToAsync", m_SendToAsyncProc);
            o.Set("ReceiveFrom", m_ReceiveFromProc);
            o.Set("ReceiveFromAsync", m_ReceiveFromAsyncProc);
            o.CrossThreading = true;
            NSJSKeyValueCollection.Set(o, new SocketContext
            {
                This   = o,
                Socket = socket,
            });
            return(o);
        }
Esempio n. 5
0
        public static NSJSObject New(NSJSVirtualMachine machine, NSJSObject context, HTTPRequest request)
        {
            if (machine == null || context == null || request == null)
            {
                return(null);
            }
            NSJSObject objective = NSJSObject.New(machine);

            objective.Set("HttpMethod", request.HttpMethod);
            objective.Set("IsLocal", request.IsLocal);
            objective.Set("KeepAlive", request.KeepAlive);
            objective.Set("ContentType", request.ContentType);
            objective.Set("CurrentContext", context);
            objective.Set("Files", ObjectAuxiliary.ToObject(machine, request.Files));
            objective.Set("InputStream", NSJSValue.NullMerge(machine, NSJSStream.New(machine, request.InputStream)));
            objective.Set("Cookies", ArrayAuxiliary.ToArray(machine, request.Cookies));
            objective.Set("RequestTraceIdentifier", request.RequestTraceIdentifier.ToString()); // "D"
            objective.Set("RemoteEndPoint", ObjectAuxiliary.ToObject(machine, request.RemoteEndPoint));
            objective.Set("ContentEncoding", NSJSEncoding.New(machine, request.ContentEncoding ?? NSJSEncoding.DefaultEncoding));
            objective.Set("Form", ObjectAuxiliary.ToObject(machine, request.Form));
            objective.Set("QueryString", ObjectAuxiliary.ToObject(machine, request.QueryString));
            objective.Set("ContentLength", Convert.ToDouble(request.ContentLength));
            objective.Set("AcceptTypes", ArrayAuxiliary.ToArray(machine, request.AcceptTypes));
            objective.Set("Path", request.Path);
            objective.Set("RawUrl", request.RawUrl);
            objective.Set("ServiceName", request.ServiceName);
            objective.Set("Url", request.Url?.ToString());
            objective.Set("UrlReferrer", request.UrlReferrer?.ToString());
            objective.Set("UserAgent", request.UserAgent);
            objective.Set("UserHostAddress", request.UserHostAddress);
            objective.Set("UserHostName", request.UserHostName);
            objective.Set("ProtocolVersion", request.ProtocolVersion.ToString());
            objective.Set("LocalEndPoint", ObjectAuxiliary.ToObject(machine, request.LocalEndPoint));
            objective.Set("UserLanguages", ArrayAuxiliary.ToArray(machine, request.UserLanguages));
            return(objective);
        }
Esempio n. 6
0
 private static void Headers(IntPtr info)
 {
     ObjectAuxiliary.GetOrSetProperty <HTTPResponse>(info, (response, arguments) => arguments.SetReturnValue(ObjectAuxiliary.
                                                                                                             ToObject(arguments.VirtualMachine, response.Headers)),
                                                     (response, arguments, objecttive) => ObjectAuxiliary.Fill(objecttive, response.Headers));
 }