introduced workaround for interop memory barrier
This commit is contained in:
@@ -36,14 +36,15 @@ public class Demo : MonoBehaviour
|
||||
//int bytes_written = zt.Send(connfd,buffer,0, out error);
|
||||
//print(bytes_written);
|
||||
|
||||
char[] buffer = new char[1024];
|
||||
buffer = "hello".ToCharArray();
|
||||
//char[] buffer = new char[1024];
|
||||
//buffer = "hello".ToCharArray();
|
||||
//print (buffer);
|
||||
//Stream stream = new MemoryStream(buffer);
|
||||
//BinaryFormatter formatter = new BinaryFormatter();
|
||||
//formatter.Serialize(stream, "HelloServer");
|
||||
//int bufferSize = 1024;
|
||||
|
||||
Debug.Log ("Sending...");
|
||||
int bytes_written = zt.Send(connfd, "hello".ToCharArray(),4, out error);
|
||||
print(bytes_written);
|
||||
}
|
||||
@@ -79,10 +80,15 @@ public class Demo : MonoBehaviour
|
||||
InputField addr = addr_go.GetComponents<InputField> () [0];
|
||||
InputField port = port_go.GetComponents<InputField> () [0];
|
||||
Debug.Log ("Connecting to: " + addr.text + ":" + port.text);
|
||||
byte error = 0;
|
||||
server_connection_socket = zt.Connect (0, addr.text, int.Parse (port.text), out error);
|
||||
Debug.Log ("server_connection_socket = " + server_connection_socket);
|
||||
Debug.Log ("Conenct(): " + error);
|
||||
|
||||
Thread connectThread = new Thread(() => {
|
||||
byte error = 0;
|
||||
server_connection_socket = zt.Connect (0, addr.text, int.Parse (port.text), out error);
|
||||
Debug.Log ("server_connection_socket = " + server_connection_socket);
|
||||
Debug.Log ("Connect(): " + error);
|
||||
});
|
||||
connectThread.IsBackground = true;
|
||||
connectThread.Start();
|
||||
}
|
||||
|
||||
public void Disconnect()
|
||||
@@ -97,12 +103,19 @@ public class Demo : MonoBehaviour
|
||||
|
||||
public void SendMessage()
|
||||
{
|
||||
//zt_test_network ();
|
||||
GameObject go = GameObject.Find ("inputMessage");
|
||||
InputField msg = go.GetComponents<InputField> () [0];
|
||||
Debug.Log ("Sending Message: " + msg.text);
|
||||
byte error = 0;
|
||||
zt.Send (server_connection_socket, msg.text.ToCharArray (), msg.text.ToCharArray ().Length, out error);
|
||||
Debug.Log ("Send(): " + error);
|
||||
|
||||
Thread sendThread = new Thread(() => {
|
||||
Debug.Log ("Sending Message: " + msg.text);
|
||||
byte error = 0;
|
||||
zt.Send (server_connection_socket, msg.text.ToCharArray (), msg.text.ToCharArray ().Length, out error);
|
||||
Debug.Log ("Send(): " + error);
|
||||
});
|
||||
sendThread.IsBackground = true;
|
||||
sendThread.Start();
|
||||
|
||||
}
|
||||
|
||||
void Start()
|
||||
@@ -116,6 +129,9 @@ public class Demo : MonoBehaviour
|
||||
go = GameObject.Find ("inputServerAddress");
|
||||
input = go.GetComponents<InputField> () [0];
|
||||
input.text = "172.22.211.245";
|
||||
go = GameObject.Find ("inputServerPort");
|
||||
input = go.GetComponents<InputField> () [0];
|
||||
input.text = "8888";
|
||||
go = GameObject.Find ("inputMessage");
|
||||
input = go.GetComponents<InputField> () [0];
|
||||
input.text = "Welcome to the machine";
|
||||
@@ -131,20 +147,30 @@ public class Demo : MonoBehaviour
|
||||
|
||||
// Terminate the ZeroTier service when the application quits
|
||||
void OnApplicationQuit() {
|
||||
Debug.Log ("OnApplicationQuit()");
|
||||
zt.Terminate ();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update () {
|
||||
|
||||
/*
|
||||
GameObject go = GameObject.Find ("_txtStatusIndicator");
|
||||
Text text = go.GetComponents<Text> () [0];
|
||||
text.text = zt.IsRunning () ? "ZeroTier Service: ONLINE" : "ZeroTier Service: OFFLINE";
|
||||
*/
|
||||
|
||||
// Rotate ZTCube when ZT is running
|
||||
/*
|
||||
if (zt.IsRunning ()) {
|
||||
GameObject go = GameObject.Find ("ZTCube");
|
||||
|
||||
|
||||
go = GameObject.Find ("ZTCube");
|
||||
Vector3 rotvec = new Vector3 (10f, 10f, 10f);
|
||||
go.transform.Rotate (rotvec, speed * Time.deltaTime);
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
GameObject go = GameObject.Find("ZTCube");
|
||||
Text text = go.GetComponents<Text> ()[0];
|
||||
|
||||
@@ -112,9 +112,9 @@ public class ZeroTierNetworkInterface {
|
||||
|
||||
// RX / TX
|
||||
[DllImport (DLL_PATH)]
|
||||
unsafe private static extern int zt_recv(int sockfd, System.IntPtr buf, int len);
|
||||
unsafe private static extern int zt_recv(int sockfd, string buf, int len);
|
||||
[DllImport (DLL_PATH)]
|
||||
unsafe private static extern int zt_send(int sockfd, System.IntPtr buf, int len);
|
||||
unsafe private static extern int zt_send(int sockfd, string buf, int len);
|
||||
|
||||
// ZT Thread controls
|
||||
[DllImport (DLL_PATH)]
|
||||
@@ -242,6 +242,7 @@ public class ZeroTierNetworkInterface {
|
||||
|
||||
// Sends data out over the network
|
||||
|
||||
/*
|
||||
public int Send(int fd, char[] buf, int len, out byte error)
|
||||
{
|
||||
int bytes_written = 0;
|
||||
@@ -249,14 +250,12 @@ public class ZeroTierNetworkInterface {
|
||||
|
||||
GCHandle buf_handle = GCHandle.Alloc (buf, GCHandleType.Pinned);
|
||||
IntPtr pBufPtr = buf_handle.AddrOfPinnedObject ();
|
||||
|
||||
//int len = Marshal.SizeOf (pBufPtr);
|
||||
if((bytes_written = zt_send (fd, pBufPtr, len)) < 0) {
|
||||
error = (byte)bytes_written;
|
||||
}
|
||||
return bytes_written;
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
// Structure used to house arrays meant to be sent to unmanaged memory and passed to the
|
||||
// ZeroTier service
|
||||
@@ -265,11 +264,26 @@ public class ZeroTierNetworkInterface {
|
||||
public IntPtr array;
|
||||
}
|
||||
|
||||
/*
|
||||
// Sends data out over the network
|
||||
// Write data to a ZeroTier socket
|
||||
public int Send(int fd, char[] buf, int len, out byte error)
|
||||
{
|
||||
//char[] buffer = new char[1024];
|
||||
GCHandle buf_handle = GCHandle.Alloc (buf, GCHandleType.Pinned);
|
||||
IntPtr pBufPtr = buf_handle.AddrOfPinnedObject ();
|
||||
|
||||
error = 0;
|
||||
int bytes_written;
|
||||
string str = new string (buf);
|
||||
if((bytes_written = zt_send (fd, str, len)) < 0) {
|
||||
error = (byte)bytes_written;
|
||||
}
|
||||
return bytes_written;
|
||||
}
|
||||
|
||||
// Sends data out over the network
|
||||
/*
|
||||
public int Send(int fd, char[] bufx, int len, out byte error)
|
||||
{
|
||||
char[] buf = "this is another test".ToCharArray();
|
||||
UnityArrayInput data = new UnityArrayInput ();
|
||||
data.array = Marshal.AllocHGlobal (Marshal.SizeOf (typeof(char))*buf.Length);
|
||||
//data.len = buf.Length;
|
||||
@@ -278,7 +292,7 @@ public class ZeroTierNetworkInterface {
|
||||
|
||||
try
|
||||
{
|
||||
Marshal.Copy(buf, 0, data.array, buf.Length);
|
||||
//Marshal.Copy(buf, 0, data.array, buf.Length);
|
||||
|
||||
Debug.Log(buf.Length);
|
||||
// ZT API call
|
||||
|
||||
Reference in New Issue
Block a user