Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/_ReSharper.Node.Net/
/**/bin/
/**/obj/
*.user
*.suo
6 changes: 0 additions & 6 deletions IronJS-Tests/IronJS-FS-Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,6 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
Expand Down
4 changes: 2 additions & 2 deletions IronJS-Tests/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ class Program
{
static void Main( string[] args ) {
Server instance = new Server();
instance.evalCommandlineArgument();
instance.runEventLoop();
instance.EvalCommandlineArgument();
instance.RunEventLoop();
}
}
}
6 changes: 0 additions & 6 deletions IronJS/Node.Net.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,6 @@
<HintPath>..\lib\ironjs-0.2-clr4-x64\IronJS.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="log.cs" />
Expand Down
9 changes: 3 additions & 6 deletions IronJS/commonjs.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
using System;
using System.IO;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Node.Net
{
class commonjs
internal static class CommonJS
{
public static Stack<string> RequireStack = new Stack<string>();
public static readonly Stack<string> RequireStack = new Stack<string>();

/**
* Find a a given js file according to CommonJS search
Expand Down
48 changes: 24 additions & 24 deletions IronJS/netserver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@
*/
namespace Node.Net
{
public class NetStream : IronJS.CommonObject
public class NetStream : CommonObject
{
// XXX making stream public to work around incomplete design - fix this
public Stream stream;

// TODO: callbacks will be JS functions, should probably use
// List<IFunction>
ArrayList dataCallbacks = new ArrayList();
ArrayList endCallbacks = new ArrayList();
readonly ArrayList dataCallbacks = new ArrayList();
readonly ArrayList endCallbacks = new ArrayList();

// TODO: this should be defined somewhere else
// Using 1k buffer - experimentally, seems to be what node.js uses
int bufferSize = 1024;
const int bufferSize = 1024;

public NetStream( Stream stream, IronJS.Environment env ) : base( env, env.Maps.Base, env.Prototypes.Object ) {
this.stream = stream;
Expand All @@ -52,7 +52,7 @@ public void ReadCallback( IAsyncResult result ) {

if( bytesRead > 0 ) {
// queue work before calling another read, could be out of order otw
Server.instance.queueWorkItem( new Callback() { name = "stream:raiseDataEvent", callback = raiseDataEvent, args = new object[] { chunk } } );
Server.Instance.QueueWorkItem( new Callback { name = "stream:raiseDataEvent", callback = raiseDataEvent, args = new object[] { chunk } } );
byte[] nextBuffer = new byte[ bufferSize ];
this.stream.BeginRead( nextBuffer, 0, bufferSize, ReadCallback, nextBuffer );
}
Expand All @@ -61,7 +61,7 @@ public void ReadCallback( IAsyncResult result ) {
// remote end of socket, not sure if raising "end" when there
// is no more data is the right thing to do. It does the right thing
// when using Telnet as the client
Server.instance.queueWorkItem( new Callback() { name = "stream:raiseEndEvent", callback = raiseEndEvent, args = new object[]{} } );
Server.Instance.QueueWorkItem( new Callback { name = "stream:raiseEndEvent", callback = raiseEndEvent, args = new object[]{} } );
}
}

Expand All @@ -76,7 +76,7 @@ public void end() {
this.stream.Close();
}
public void addListener( string eventname, IronJS.FunctionObject callback ) {
Server.instance.Listeners++;
Server.Instance.Listeners++;
log.Trace( "NetStream: adding listener: " + eventname );
if( eventname == "data" ) {
dataCallbacks.Add( callback );
Expand All @@ -87,11 +87,11 @@ public void addListener( string eventname, IronJS.FunctionObject callback ) {
}
public void removeAllListeners( string eventname ) {
if( eventname == "data" ) {
Server.instance.Listeners -= dataCallbacks.Count;
Server.Instance.Listeners -= dataCallbacks.Count;
dataCallbacks.Clear();
}
else if( eventname == "end" ) {
Server.instance.Listeners -= endCallbacks.Count;
Server.Instance.Listeners -= endCallbacks.Count;
endCallbacks.Clear();
}
}
Expand Down Expand Up @@ -129,13 +129,13 @@ public void raiseEndEvent( object[] args ) {

} // class

public class NetServer : IronJS.CommonObject
public class NetServer : CommonObject
{
TcpListener tcpServer;

ArrayList listeningCallbacks = new ArrayList();
ArrayList connectionCallbacks = new ArrayList();
ArrayList closeCallbacks = new ArrayList();
readonly ArrayList listeningCallbacks = new ArrayList();
readonly ArrayList connectionCallbacks = new ArrayList();
readonly ArrayList closeCallbacks = new ArrayList();

public NetServer( IronJS.FunctionObject callback, IronJS.Environment env ) : base( env, env.Maps.Base, env.Prototypes.Object ) {
// have to set this stuff up. not sure why yet
Expand All @@ -162,7 +162,7 @@ public CommonObject listen( object in_port, string host ) {
this.tcpServer = new TcpListener( ipAddress, port );
log.Trace( "net.Server.listen(): starting tcp server" );
this.tcpServer.Start();
Server.instance.queueWorkItem( new Callback { callback = raiseListeningEvent, args = new object[]{} } );
Server.Instance.QueueWorkItem( new Callback { callback = raiseListeningEvent, args = new object[]{} } );
this.tcpServer.BeginAcceptTcpClient( listenerCallback, null );
return this;
}
Expand All @@ -175,7 +175,7 @@ public void listenerCallback( IAsyncResult result ) {

TcpClient client = this.tcpServer.EndAcceptTcpClient( result );
NetStream stream = new NetStream( client.GetStream(), Env );
Server.instance.queueWorkItem( new Callback { callback = raiseConnectionEvent, args = new object[]{ stream } } );
Server.Instance.QueueWorkItem( new Callback { callback = raiseConnectionEvent, args = new object[]{ stream } } );

// kick off async read
stream.read();
Expand Down Expand Up @@ -209,28 +209,28 @@ public void raiseConnectionEvent( object[] args ) {
func.Compiler.compileAs<Action<IronJS.FunctionObject,IronJS.CommonObject,IronJS.CommonObject>>(func);
fun.Invoke(func, this, stream );
*/
func.Call<NetStream>( this, stream );
func.Call( this, stream );
}
}

public void removeAllListeners( string eventname ) {
if( eventname == "listening" ) {
Server.instance.Listeners -= listeningCallbacks.Count;
Server.Instance.Listeners -= listeningCallbacks.Count;
listeningCallbacks.Clear();
}
else if( eventname == "connection" ) {
Server.instance.Listeners -= connectionCallbacks.Count;
Server.Instance.Listeners -= connectionCallbacks.Count;
connectionCallbacks.Clear();
}
else if( eventname == "close" ) {
Server.instance.Listeners -= closeCallbacks.Count;
Server.Instance.Listeners -= closeCallbacks.Count;
closeCallbacks.Clear();
}
}

public void addListener( string eventname, IronJS.FunctionObject callback) {
log.Trace( "NetServer - adding listener: " + eventname );
Server.instance.Listeners++;
Server.Instance.Listeners++;
if( eventname == "listening" ) {
listeningCallbacks.Add( callback );
}
Expand All @@ -248,19 +248,19 @@ public void addListener( string eventname, IronJS.FunctionObject callback) {

// provides the 'net' namespace
// TODO: rename this class
public class net : IronJS.CommonObject
public class net : CommonObject
{
public net( IronJS.Environment env )
: base( env, env.Maps.Base, env.Prototypes.Object ) {

var objMethod = Utils.createHostFunction<Func<IronJS.FunctionObject, IronJS.CommonObject>>( Env, CreateServer );
var objMethod = Utils.createHostFunction<Func<FunctionObject, CommonObject>>( Env, CreateServer );
log.Trace( objMethod );
this.Put( "createServer", objMethod );
}

public IronJS.CommonObject CreateServer( IronJS.FunctionObject callback ) {
public CommonObject CreateServer( FunctionObject callback ) {
log.Trace( "net.createServer() called." );
Net.NetServer server = new Net.NetServer( callback, Env );
NetServer server = new Net.NetServer( callback, Env );
log.Trace( server );
return ( server );
}
Expand Down
Loading