forked from mysql-net/MySqlConnector
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3f92919
commit 1ac303e
Showing
4 changed files
with
248 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
namespace MySql.Data.Serialization | ||
{ | ||
/// <summary> | ||
/// Specifies whether to perform synchronous or asynchronous I/O. | ||
/// </summary> | ||
internal enum ConnectionType | ||
{ | ||
/// <summary> | ||
/// Connection is a TCP connection. | ||
/// </summary> | ||
Tcp, | ||
|
||
/// <summary> | ||
/// Connection is a Unix Domain Socket. | ||
/// </summary> | ||
Unix, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
using System; | ||
using System.Net; | ||
using System.Net.Sockets; | ||
using System.Text; | ||
|
||
namespace MySql.Data | ||
{ | ||
// copied from https://github.com/mono/mono/blob/master/mcs/class/Mono.Posix/Mono.Unix/UnixEndPoint.cs | ||
#if NETSTANDARD1_3 | ||
#else | ||
[Serializable] | ||
#endif | ||
public class UnixEndPoint : EndPoint | ||
{ | ||
string filename; | ||
|
||
public UnixEndPoint (string filename) | ||
{ | ||
if (filename == null) | ||
throw new ArgumentNullException ("filename"); | ||
|
||
if (filename == "") | ||
throw new ArgumentException ("Cannot be empty.", "filename"); | ||
this.filename = filename; | ||
} | ||
|
||
public string Filename { | ||
get { | ||
return(filename); | ||
} | ||
set { | ||
filename=value; | ||
} | ||
} | ||
|
||
public override AddressFamily AddressFamily { | ||
get { return AddressFamily.Unix; } | ||
} | ||
|
||
public override EndPoint Create (SocketAddress socketAddress) | ||
{ | ||
/* | ||
* Should also check this | ||
* | ||
int addr = (int) AddressFamily.Unix; | ||
if (socketAddress [0] != (addr & 0xFF)) | ||
throw new ArgumentException ("socketAddress is not a unix socket address."); | ||
if (socketAddress [1] != ((addr & 0xFF00) >> 8)) | ||
throw new ArgumentException ("socketAddress is not a unix socket address."); | ||
*/ | ||
|
||
if (socketAddress.Size == 2) { | ||
// Empty filename. | ||
// Probably from RemoteEndPoint which on linux does not return the file name. | ||
UnixEndPoint uep = new UnixEndPoint ("a"); | ||
uep.filename = ""; | ||
return uep; | ||
} | ||
int size = socketAddress.Size - 2; | ||
byte [] bytes = new byte [size]; | ||
for (int i = 0; i < bytes.Length; i++) { | ||
bytes [i] = socketAddress [i + 2]; | ||
// There may be junk after the null terminator, so ignore it all. | ||
if (bytes [i] == 0) { | ||
size = i; | ||
break; | ||
} | ||
} | ||
|
||
string name = Encoding.UTF8.GetString (bytes, 0, size); | ||
return new UnixEndPoint (name); | ||
} | ||
|
||
public override SocketAddress Serialize () | ||
{ | ||
byte [] bytes = Encoding.UTF8.GetBytes (filename); | ||
SocketAddress sa = new SocketAddress (AddressFamily, 2 + bytes.Length + 1); | ||
// sa [0] -> family low byte, sa [1] -> family high byte | ||
for (int i = 0; i < bytes.Length; i++) | ||
sa [2 + i] = bytes [i]; | ||
|
||
//NULL suffix for non-abstract path | ||
sa[2 + bytes.Length] = 0; | ||
|
||
return sa; | ||
} | ||
|
||
public override string ToString() { | ||
return(filename); | ||
} | ||
|
||
public override int GetHashCode () | ||
{ | ||
return filename.GetHashCode (); | ||
} | ||
|
||
public override bool Equals (object o) | ||
{ | ||
UnixEndPoint other = o as UnixEndPoint; | ||
if (other == null) | ||
return false; | ||
|
||
return (other.filename == filename); | ||
} | ||
} | ||
} |