113 |
if(!SocketMethods.Create((int)addressFamily, (int)socketType, |
if(!SocketMethods.Create((int)addressFamily, (int)socketType, |
114 |
(int)protocolType, out handle)) |
(int)protocolType, out handle)) |
115 |
{ |
{ |
116 |
throw new SocketException(SocketMethods.GetErrno()); |
throw new SocketException(this.GetErrno()); |
117 |
} |
} |
118 |
} |
} |
119 |
private Socket(AddressFamily addressFamily, SocketType socketType, |
private Socket(AddressFamily addressFamily, SocketType socketType, |
145 |
GC.SuppressFinalize(this); |
GC.SuppressFinalize(this); |
146 |
} |
} |
147 |
|
|
148 |
|
// Get the current errno condition. |
149 |
|
private Errno GetErrno() |
150 |
|
{ |
151 |
|
// get the errno condition |
152 |
|
Errno errno = SocketMethods.GetErrno(); |
153 |
|
|
154 |
|
// disconnect as required |
155 |
|
switch(errno) |
156 |
|
{ |
157 |
|
case Errno.EPIPE: |
158 |
|
case Errno.ECONNABORTED: |
159 |
|
case Errno.ECONNRESET: |
160 |
|
case Errno.ETIMEDOUT: |
161 |
|
case Errno.ECONNREFUSED: |
162 |
|
case Errno.EHOSTDOWN: |
163 |
|
{ |
164 |
|
connected = false; |
165 |
|
} |
166 |
|
break; |
167 |
|
} |
168 |
|
|
169 |
|
// return the errno condition |
170 |
|
return errno; |
171 |
|
} |
172 |
|
|
173 |
// Accept an incoming connection on this socket. |
// Accept an incoming connection on this socket. |
174 |
public Socket Accept() |
public Socket Accept() |
175 |
{ |
{ |
199 |
if(!SocketMethods.Accept |
if(!SocketMethods.Accept |
200 |
(currentHandle, addrReturn, out newHandle)) |
(currentHandle, addrReturn, out newHandle)) |
201 |
{ |
{ |
202 |
throw new SocketException(SocketMethods.GetErrno()); |
throw new SocketException(this.GetErrno()); |
203 |
} |
} |
204 |
|
|
205 |
// Create the end-point object for the remote side. |
// Create the end-point object for the remote side. |
684 |
// Bind the address to the socket. |
// Bind the address to the socket. |
685 |
if(!SocketMethods.Bind(handle, addr)) |
if(!SocketMethods.Bind(handle, addr)) |
686 |
{ |
{ |
687 |
throw new SocketException(SocketMethods.GetErrno()); |
throw new SocketException(this.GetErrno()); |
688 |
} |
} |
689 |
|
|
690 |
// Record the local end point for later. |
// Record the local end point for later. |
728 |
// Connect to the foreign location. |
// Connect to the foreign location. |
729 |
if(!SocketMethods.Connect(handle, addr)) |
if(!SocketMethods.Connect(handle, addr)) |
730 |
{ |
{ |
731 |
throw new SocketException(SocketMethods.GetErrno()); |
throw new SocketException(this.GetErrno()); |
732 |
} |
} |
733 |
connected = true; |
connected = true; |
734 |
this.remoteEP = remoteEP; |
this.remoteEP = remoteEP; |
770 |
(handle, (int)optionLevel, (int)optionName, |
(handle, (int)optionLevel, (int)optionName, |
771 |
out optionValue)) |
out optionValue)) |
772 |
{ |
{ |
773 |
throw new SocketException(SocketMethods.GetErrno()); |
throw new SocketException(this.GetErrno()); |
774 |
} |
} |
775 |
return optionValue; |
return optionValue; |
776 |
} |
} |
810 |
(handle, out enabled, out seconds)) |
(handle, out enabled, out seconds)) |
811 |
{ |
{ |
812 |
throw new SocketException |
throw new SocketException |
813 |
(SocketMethods.GetErrno()); |
(this.GetErrno()); |
814 |
} |
} |
815 |
return ((enabled && seconds == 0) ? 1 : 0); |
return ((enabled && seconds == 0) ? 1 : 0); |
816 |
} |
} |
829 |
(handle, out enabled, out seconds)) |
(handle, out enabled, out seconds)) |
830 |
{ |
{ |
831 |
throw new SocketException |
throw new SocketException |
832 |
(SocketMethods.GetErrno()); |
(this.GetErrno()); |
833 |
} |
} |
834 |
return new LingerOption(enabled, seconds); |
return new LingerOption(enabled, seconds); |
835 |
} |
} |
885 |
group, mcint)) |
group, mcint)) |
886 |
{ |
{ |
887 |
throw new SocketException |
throw new SocketException |
888 |
(SocketMethods.GetErrno()); |
(this.GetErrno()); |
889 |
} |
} |
890 |
return new MulticastOption |
return new MulticastOption |
891 |
((new SocketAddress(group)).IPAddress, |
((new SocketAddress(group)).IPAddress, |
925 |
if(!SocketMethods.DiscoverIrDADevices(handle, data)) |
if(!SocketMethods.DiscoverIrDADevices(handle, data)) |
926 |
{ |
{ |
927 |
throw new SocketException |
throw new SocketException |
928 |
(SocketMethods.GetErrno()); |
(this.GetErrno()); |
929 |
} |
} |
930 |
return data; |
return data; |
931 |
} |
} |
962 |
// Perform a listen on the socket. |
// Perform a listen on the socket. |
963 |
if(!SocketMethods.Listen(handle, backlog)) |
if(!SocketMethods.Listen(handle, backlog)) |
964 |
{ |
{ |
965 |
throw new SocketException(SocketMethods.GetErrno()); |
throw new SocketException(this.GetErrno()); |
966 |
} |
} |
967 |
} |
} |
968 |
} |
} |
1016 |
} |
} |
1017 |
else if(result < 0) |
else if(result < 0) |
1018 |
{ |
{ |
1019 |
throw new SocketException(SocketMethods.GetErrno()); |
throw new SocketException(this.GetErrno()); |
1020 |
} |
} |
1021 |
else |
else |
1022 |
{ |
{ |
1045 |
(handle, buffer, offset, size, (int)socketFlags); |
(handle, buffer, offset, size, (int)socketFlags); |
1046 |
if(result < 0) |
if(result < 0) |
1047 |
{ |
{ |
1048 |
throw new SocketException(SocketMethods.GetErrno()); |
throw new SocketException(this.GetErrno()); |
1049 |
} |
} |
1050 |
else |
else |
1051 |
{ |
{ |
1109 |
(int)socketFlags, addrReturn); |
(int)socketFlags, addrReturn); |
1110 |
if(result < 0) |
if(result < 0) |
1111 |
{ |
{ |
1112 |
throw new SocketException(SocketMethods.GetErrno()); |
throw new SocketException(this.GetErrno()); |
1113 |
} |
} |
1114 |
else |
else |
1115 |
{ |
{ |
1367 |
(handle, buffer, offset, size, (int)socketFlags); |
(handle, buffer, offset, size, (int)socketFlags); |
1368 |
if(result < 0) |
if(result < 0) |
1369 |
{ |
{ |
1370 |
throw new SocketException(SocketMethods.GetErrno()); |
throw new SocketException(this.GetErrno()); |
1371 |
} |
} |
1372 |
else |
else |
1373 |
{ |
{ |
1429 |
(handle, buffer, offset, size, (int)socketFlags, addr); |
(handle, buffer, offset, size, (int)socketFlags, addr); |
1430 |
if(result < 0) |
if(result < 0) |
1431 |
{ |
{ |
1432 |
throw new SocketException(SocketMethods.GetErrno()); |
throw new SocketException(this.GetErrno()); |
1433 |
} |
} |
1434 |
else |
else |
1435 |
{ |
{ |
1478 |
(handle, (int)optionLevel, (int)optionName, |
(handle, (int)optionLevel, (int)optionName, |
1479 |
optionValue)) |
optionValue)) |
1480 |
{ |
{ |
1481 |
throw new SocketException(SocketMethods.GetErrno()); |
throw new SocketException(this.GetErrno()); |
1482 |
} |
} |
1483 |
} |
} |
1484 |
} |
} |
1598 |
linger.LingerTime)) |
linger.LingerTime)) |
1599 |
{ |
{ |
1600 |
throw new SocketException |
throw new SocketException |
1601 |
(SocketMethods.GetErrno()); |
(this.GetErrno()); |
1602 |
} |
} |
1603 |
} |
} |
1604 |
return; |
return; |
1635 |
group, mcint)) |
group, mcint)) |
1636 |
{ |
{ |
1637 |
throw new SocketException |
throw new SocketException |
1638 |
(SocketMethods.GetErrno()); |
(this.GetErrno()); |
1639 |
} |
} |
1640 |
} |
} |
1641 |
return; |
return; |
1656 |
} |
} |
1657 |
if(!SocketMethods.Shutdown(handle, (int)how)) |
if(!SocketMethods.Shutdown(handle, (int)how)) |
1658 |
{ |
{ |
1659 |
throw new SocketException(SocketMethods.GetErrno()); |
throw new SocketException(this.GetErrno()); |
1660 |
} |
} |
1661 |
} |
} |
1662 |
} |
} |
1704 |
if(result < 0) |
if(result < 0) |
1705 |
{ |
{ |
1706 |
throw new SocketException |
throw new SocketException |
1707 |
(SocketMethods.GetErrno()); |
(this.GetErrno()); |
1708 |
} |
} |
1709 |
else |
else |
1710 |
{ |
{ |
1821 |
if(!SocketMethods.GetSockName(handle, addrReturn)) |
if(!SocketMethods.GetSockName(handle, addrReturn)) |
1822 |
{ |
{ |
1823 |
throw new SocketException |
throw new SocketException |
1824 |
(SocketMethods.GetErrno()); |
(this.GetErrno()); |
1825 |
} |
} |
1826 |
|
|
1827 |
// Create a new end-point object using addrReturn. |
// Create a new end-point object using addrReturn. |