You've already forked linux-packaging-mono
Imported Upstream version 5.14.0.78
Former-commit-id: 3494343bcc9ddb42b36b82dd9ae7b69e85e0229f
This commit is contained in:
parent
74b74abd9f
commit
19234507ba
@@ -30,13 +30,12 @@ TEST_RESOURCES = \
|
||||
|
||||
USE_XTEST_REMOTE_EXECUTOR = YES
|
||||
XTEST_LIB_REFS = System System.Core System.Net Facades/System.Threading.Tasks Facades/System.Runtime.InteropServices.RuntimeInformation System.Net.Http
|
||||
LIB_MCS_FLAGS = -d:CONFIGURATION_2_0 $(REFERENCE_SOURCES_FLAGS) -unsafe $(RESOURCE_FILES:%=-resource:%) -nowarn:436
|
||||
LIB_MCS_FLAGS = -d:COREFX -d:CONFIGURATION_2_0 -d:XML_DEP -d:SECURITY_DEP $(REFERENCE_SOURCES_FLAGS) -unsafe $(RESOURCE_FILES:%=-resource:%) -nowarn:436
|
||||
|
||||
ifndef NO_MONO_SECURITY
|
||||
MONO_SECURITY=Mono.Security
|
||||
MONO_SECURITY_REF=MonoSecurity=Mono.Security
|
||||
MONO_SECURITY_DLL=$(the_libdir_base)Mono.Security.dll
|
||||
EXTERN_ALIAS_FLAGS = -d:MONO_SECURITY_ALIAS
|
||||
MONO_SECURITY := Mono.Security
|
||||
LIB_MCS_FLAGS += -d:MONO_SECURITY_ALIAS
|
||||
LIB_REFS += MonoSecurity=Mono.Security
|
||||
else
|
||||
LIB_MCS_FLAGS += -d:INSIDE_SYSTEM
|
||||
endif
|
||||
@@ -69,6 +68,10 @@ ifdef MONO_FEATURE_APPLETLS
|
||||
LIB_MCS_FLAGS += -d:MONO_FEATURE_APPLETLS
|
||||
endif
|
||||
|
||||
ifndef AOT_FRIENDLY_PROFILE
|
||||
LIB_MCS_FLAGS += -d:FEATURE_COMPILED
|
||||
endif
|
||||
|
||||
ifdef ONLY_APPLETLS
|
||||
LIB_MCS_FLAGS += -d:ONLY_APPLETLS
|
||||
endif
|
||||
@@ -99,34 +102,17 @@ endif
|
||||
TXT_RESOURCE_STRINGS = ../referencesource/System/System.txt
|
||||
|
||||
|
||||
API_BIN_REFS := System.Net.Http
|
||||
|
||||
#
|
||||
# Flags used to build the secxml version of System.
|
||||
#
|
||||
ifeq (secxml/, $(intermediate))
|
||||
LOCAL_MCS_FLAGS =
|
||||
LIB_REFS += bare/System.Xml $(MONO_SECURITY_REF)
|
||||
LIB_MCS_FLAGS += -d:SECURITY_DEP -d:XML_DEP $(EXTERN_ALIAS_FLAGS)
|
||||
endif
|
||||
|
||||
#
|
||||
# Flags used to build the final version of System (when intermediate is not defined)
|
||||
#
|
||||
ifndef intermediate
|
||||
LIB_REFS += System.Xml $(MONO_SECURITY_REF)
|
||||
LIB_MCS_FLAGS += -d:SECURITY_DEP -d:XML_DEP $(EXTERN_ALIAS_FLAGS)
|
||||
API_BIN_REFS := System.Net.Http System.Xml
|
||||
|
||||
ifndef MOBILE_PROFILE
|
||||
LIB_REFS += System.Configuration
|
||||
API_BIN_REFS += System.Configuration
|
||||
LIB_MCS_FLAGS += -d:CONFIGURATION_DEP
|
||||
endif
|
||||
|
||||
endif
|
||||
|
||||
EXTRA_DISTFILES = \
|
||||
common.sources \
|
||||
common_networking.sources \
|
||||
corefx.unix.sources \
|
||||
Test/test-config-file \
|
||||
Test/System.Security.Cryptography.X509Certificates/pkits/Makefile \
|
||||
Test/System.Security.Cryptography.X509Certificates/pkits/README \
|
||||
@@ -136,69 +122,8 @@ EXTRA_DISTFILES = \
|
||||
|
||||
include ../../build/library.make
|
||||
|
||||
system_library_deps := \
|
||||
$(secxml_libdir)/System.dll \
|
||||
$(the_libdir_base)System.Xml.dll \
|
||||
$(MONO_SECURITY_DLL) \
|
||||
$(bare_libdir)/System.dll
|
||||
|
||||
ifndef MOBILE_PROFILE
|
||||
system_library_deps += $(the_libdir_base)System.Configuration.dll
|
||||
endif
|
||||
|
||||
artifacts = $(system_library_deps) \
|
||||
$(bare_libdir)/System.Xml.dll \
|
||||
$(MONO_SECURITY_DLL) \
|
||||
$(the_libdir_base)System.Configuration.dll
|
||||
|
||||
.NOTPARALLEL: $(system_library_deps)
|
||||
|
||||
$(the_libdir_base)System.dll: $(system_library_deps) ../Mono.Security/Makefile
|
||||
|
||||
ifeq (bare/,$(intermediate))
|
||||
build-bare:
|
||||
else
|
||||
$(bare_libdir)/System.dll:
|
||||
$(MAKE) intermediate=bare/ $(bare_libdir)/System.dll
|
||||
endif
|
||||
|
||||
ifneq (secxml/,$(intermediate))
|
||||
$(secxml_libdir)/System.dll: $(bare_libdir)/System.dll $(bare_libdir)/System.Xml.dll $(MONO_SECURITY_DLL) $(bare_libdir)/System.dll
|
||||
$(MAKE) intermediate=secxml/ $(secxml_libdir)/System.dll
|
||||
else
|
||||
build-sec:
|
||||
endif
|
||||
|
||||
$(the_libdir_base)System.Xml.dll:
|
||||
(cd ../System.XML; $(MAKE) $@)
|
||||
|
||||
$(bare_libdir)/System.Xml.dll:
|
||||
(cd ../System.XML; $(MAKE) $@)
|
||||
|
||||
$(the_libdir_base)Mono.Security.dll: ../Mono.Security/Makefile
|
||||
(cd ../Mono.Security; $(MAKE))
|
||||
|
||||
$(the_libdir_base)System.Configuration.dll:
|
||||
(cd ../System.Configuration; $(MAKE))
|
||||
|
||||
$(build_lib): $(CYCLIC_DEP_FILES)
|
||||
|
||||
$(test_lib_output): $(TEST_RESOURCES) $(test_lib_dir)
|
||||
|
||||
CLEAN_FILES = $(test_lib).config $(bare_libdir)/System.dll $(secxml_libdir)/System.dll $(bare_libdir)/System.dll.mdb $(secxml_libdir)/System.dll.mdb
|
||||
|
||||
# Helper target to run the perl regex test suite
|
||||
regex-check:
|
||||
$(MAKE) check FIXTURE=System.Text.RegularExpressions.PerlTest
|
||||
|
||||
#Debuging target
|
||||
fresh: clean
|
||||
rm -rf ../../class/lib/$(PROFILE)/bare ../../class/lib/$(PROFILE)/bare/ $(system_library_deps)
|
||||
|
||||
ifndef intermediate
|
||||
ifneq ($(PROFILE),basic)
|
||||
csproj-local:
|
||||
$(MAKE) csproj-local intermediate=bare/
|
||||
$(MAKE) csproj-local intermediate=secxml/
|
||||
endif
|
||||
endif
|
||||
|
189
mcs/class/System/System.IO/CoreFXFileSystemWatcherProxy.cs
Normal file
189
mcs/class/System/System.IO/CoreFXFileSystemWatcherProxy.cs
Normal file
@@ -0,0 +1,189 @@
|
||||
// Bridges the Mono and CoreFX FileSystemWatcher types.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
using C = System.IO.CoreFX.FileSystemWatcher;
|
||||
using M = System.IO.FileSystemWatcher;
|
||||
using Handle = System.Object;
|
||||
|
||||
namespace System.IO {
|
||||
|
||||
internal class CoreFXFileSystemWatcherProxy : IFileWatcher
|
||||
{
|
||||
static IFileWatcher instance; // Mono FSW objects -> this
|
||||
static IDictionary<Handle, C> internal_map; // this -> CoreFX FSW objects
|
||||
static ConditionalWeakTable<Handle, M> external_map; // this -> Mono FSW objects
|
||||
static IDictionary<object, Handle> event_map; // CoreFX FSW events -> this
|
||||
|
||||
const int INTERRUPT_MS = 300;
|
||||
|
||||
protected void Operation (Action<IDictionary<object, C>, ConditionalWeakTable<object, M>, IDictionary<object, object>, Handle> map_op = null, Action<C, M> object_op = null, object handle = null, Action<C, M> cancel_op = null)
|
||||
{
|
||||
C internal_fsw = null;
|
||||
M fsw = null;
|
||||
bool live, havelock;
|
||||
|
||||
if (cancel_op != null) { // highest priority and must not lock
|
||||
havelock = Monitor.TryEnter (instance, INTERRUPT_MS);
|
||||
live = (handle != null && (internal_map.TryGetValue (handle, out internal_fsw) || external_map.TryGetValue (handle, out fsw))) ;
|
||||
if (live && havelock)
|
||||
try { cancel_op (internal_fsw, fsw); }
|
||||
catch (Exception) { };
|
||||
|
||||
if (havelock)
|
||||
Monitor.Exit (instance);
|
||||
if (live && !havelock)
|
||||
try {
|
||||
var t = Task<bool>.Run( () => { cancel_op (internal_fsw, fsw); return true;});
|
||||
t.Wait (INTERRUPT_MS);
|
||||
}
|
||||
catch (Exception) { };
|
||||
return;
|
||||
}
|
||||
if (map_op != null && handle == null) {
|
||||
lock (instance) {
|
||||
try { map_op (internal_map, external_map, event_map, null); }
|
||||
catch (Exception e) { throw new InvalidOperationException (nameof(map_op), e); }
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (handle == null)
|
||||
return;
|
||||
|
||||
lock (instance) {
|
||||
live = (internal_map.TryGetValue (handle, out internal_fsw) && external_map.TryGetValue (handle, out fsw)) ;
|
||||
if (live && map_op != null) {
|
||||
try { map_op (internal_map, external_map, event_map, handle); }
|
||||
catch (Exception e) { throw new InvalidOperationException (nameof(map_op), e); };
|
||||
}
|
||||
}
|
||||
if (!live || object_op == null)
|
||||
return;
|
||||
|
||||
try { object_op (internal_fsw, fsw); }
|
||||
catch (Exception e) { throw new InvalidOperationException (nameof(object_op), e); };
|
||||
}
|
||||
|
||||
protected void ProxyDispatch (object sender, FileAction action, FileSystemEventArgs args)
|
||||
{
|
||||
RenamedEventArgs renamed =
|
||||
action == FileAction.RenamedNewName ? (RenamedEventArgs) args : null;
|
||||
|
||||
object handle = null;
|
||||
|
||||
Operation (map_op: (in_map, out_map, event_map, h) => event_map.TryGetValue (sender, out handle));
|
||||
|
||||
Operation (object_op: (_, fsw) => {
|
||||
if (!fsw.EnableRaisingEvents)
|
||||
return;
|
||||
fsw.DispatchEvents (action, args.Name, ref renamed);
|
||||
if (fsw.Waiting) {
|
||||
fsw.Waiting = false;
|
||||
System.Threading.Monitor.PulseAll (fsw);
|
||||
}
|
||||
}, handle: handle);
|
||||
}
|
||||
|
||||
protected void ProxyDispatchError (object sender, ErrorEventArgs args)
|
||||
{
|
||||
object handle = null;
|
||||
|
||||
Operation (map_op: (in_map, out_map, event_map, _) => event_map.TryGetValue (sender, out handle));
|
||||
|
||||
Operation (object_op: (_, fsw) => fsw.DispatchErrorEvents (args),
|
||||
handle: handle);
|
||||
}
|
||||
|
||||
public object NewWatcher (M fsw)
|
||||
{
|
||||
var handle = new object ();
|
||||
var result = new C ();
|
||||
|
||||
result.Changed += (object o, FileSystemEventArgs args) =>
|
||||
{ ProxyDispatch (o, FileAction.Modified, args); };
|
||||
result.Created += (object o, FileSystemEventArgs args) =>
|
||||
{ ProxyDispatch (o, FileAction.Added, args); };
|
||||
result.Deleted += (object o, FileSystemEventArgs args) =>
|
||||
{ ProxyDispatch (o, FileAction.Removed, args); };
|
||||
result.Renamed += (object o, RenamedEventArgs args) =>
|
||||
{ ProxyDispatch (o, FileAction.RenamedNewName, args); };
|
||||
|
||||
result.Error += (object o, ErrorEventArgs args) =>
|
||||
{ ProxyDispatchError (handle, args); };
|
||||
|
||||
Operation (map_op: (in_map, out_map, event_map, _) => {
|
||||
in_map.Add (handle, result);
|
||||
out_map.Add (handle, fsw);
|
||||
event_map.Add (result, handle);
|
||||
});
|
||||
|
||||
return handle;
|
||||
}
|
||||
|
||||
public void StartDispatching (object handle)
|
||||
{
|
||||
if (handle == null)
|
||||
return;
|
||||
|
||||
Operation (object_op: (internal_fsw, fsw) => {
|
||||
internal_fsw.Path = fsw.Path;
|
||||
internal_fsw.Filter = fsw.Filter;
|
||||
internal_fsw.IncludeSubdirectories = fsw.IncludeSubdirectories;
|
||||
internal_fsw.InternalBufferSize = fsw.InternalBufferSize;
|
||||
internal_fsw.NotifyFilter = fsw.NotifyFilter;
|
||||
internal_fsw.Site = fsw.Site;
|
||||
internal_fsw.EnableRaisingEvents = true;
|
||||
}, handle: handle);
|
||||
}
|
||||
|
||||
public void StopDispatching (object handle)
|
||||
{
|
||||
if (handle == null)
|
||||
return;
|
||||
|
||||
Operation (handle: handle,
|
||||
cancel_op: (internal_fsw, fsw) =>
|
||||
{
|
||||
if (internal_fsw != null)
|
||||
internal_fsw.EnableRaisingEvents = false;
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
public void Dispose (object handle)
|
||||
{
|
||||
if (handle == null)
|
||||
return;
|
||||
|
||||
Operation (handle: handle,
|
||||
cancel_op: (internal_fsw, fsw) => {
|
||||
if (internal_fsw != null)
|
||||
internal_fsw.Dispose ();
|
||||
var inner_key = internal_map [handle];
|
||||
internal_map.Remove (handle);
|
||||
external_map.Remove (handle);
|
||||
event_map.Remove (inner_key);
|
||||
handle = null;
|
||||
});
|
||||
}
|
||||
|
||||
public static bool GetInstance (out IFileWatcher watcher)
|
||||
{
|
||||
if (instance != null) {
|
||||
watcher = instance;
|
||||
return true;
|
||||
}
|
||||
|
||||
internal_map = new ConcurrentDictionary <object, C> ();
|
||||
external_map = new ConditionalWeakTable <object, M> ();
|
||||
event_map = new ConcurrentDictionary <object, object> ();
|
||||
instance = watcher = new CoreFXFileSystemWatcherProxy ();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
@@ -79,8 +79,9 @@ namespace System.IO {
|
||||
return true;
|
||||
}
|
||||
|
||||
public void StartDispatching (FileSystemWatcher fsw)
|
||||
public void StartDispatching (object handle)
|
||||
{
|
||||
var fsw = handle as FileSystemWatcher;
|
||||
DefaultWatcherData data;
|
||||
lock (this) {
|
||||
if (watches == null)
|
||||
@@ -116,8 +117,9 @@ namespace System.IO {
|
||||
}
|
||||
}
|
||||
|
||||
public void StopDispatching (FileSystemWatcher fsw)
|
||||
public void StopDispatching (object handle)
|
||||
{
|
||||
var fsw = handle as FileSystemWatcher;
|
||||
DefaultWatcherData data;
|
||||
lock (this) {
|
||||
if (watches == null) return;
|
||||
@@ -132,6 +134,11 @@ namespace System.IO {
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose (object handle)
|
||||
{
|
||||
// does nothing
|
||||
}
|
||||
|
||||
|
||||
void Monitor ()
|
||||
{
|
||||
|
@@ -110,8 +110,9 @@ namespace System.IO {
|
||||
return true;
|
||||
}
|
||||
|
||||
public void StartDispatching (FileSystemWatcher fsw)
|
||||
public void StartDispatching (object handle)
|
||||
{
|
||||
var fsw = handle as FileSystemWatcher;
|
||||
FAMData data;
|
||||
lock (this) {
|
||||
if (thread == null) {
|
||||
@@ -199,8 +200,9 @@ namespace System.IO {
|
||||
}
|
||||
}
|
||||
|
||||
public void StopDispatching (FileSystemWatcher fsw)
|
||||
public void StopDispatching (object handle)
|
||||
{
|
||||
var fsw = handle as FileSystemWatcher;
|
||||
FAMData data;
|
||||
lock (this) {
|
||||
data = (FAMData) watches [fsw];
|
||||
@@ -408,6 +410,10 @@ namespace System.IO {
|
||||
return fam_Pending (ref fc);
|
||||
}
|
||||
|
||||
public void Dispose (object handle)
|
||||
{
|
||||
// does nothing
|
||||
}
|
||||
|
||||
|
||||
[DllImport ("libfam.so.0", EntryPoint="FAMOpen")]
|
||||
|
@@ -45,6 +45,8 @@ namespace System.IO {
|
||||
|
||||
#region Fields
|
||||
|
||||
bool inited;
|
||||
bool start_requested;
|
||||
bool enableRaisingEvents;
|
||||
string filter;
|
||||
bool includeSubdirectories;
|
||||
@@ -59,6 +61,7 @@ namespace System.IO {
|
||||
bool disposed;
|
||||
string mangledFilter;
|
||||
static IFileWatcher watcher;
|
||||
object watcher_handle;
|
||||
static object lockobj = new object ();
|
||||
|
||||
#endregion // Fields
|
||||
@@ -95,6 +98,8 @@ namespace System.IO {
|
||||
if (!Directory.Exists (path))
|
||||
throw new ArgumentException ("Directory does not exist", "path");
|
||||
|
||||
this.inited = false;
|
||||
this.start_requested = false;
|
||||
this.enableRaisingEvents = false;
|
||||
this.filter = filter;
|
||||
this.includeSubdirectories = false;
|
||||
@@ -121,28 +126,39 @@ namespace System.IO {
|
||||
switch (mode) {
|
||||
case 1: // windows
|
||||
ok = DefaultWatcher.GetInstance (out watcher);
|
||||
//ok = WindowsWatcher.GetInstance (out watcher);
|
||||
watcher_handle = this;
|
||||
break;
|
||||
case 2: // libfam
|
||||
ok = FAMWatcher.GetInstance (out watcher, false);
|
||||
watcher_handle = this;
|
||||
break;
|
||||
case 3: // kevent
|
||||
ok = KeventWatcher.GetInstance (out watcher);
|
||||
watcher_handle = this;
|
||||
break;
|
||||
case 4: // libgamin
|
||||
ok = FAMWatcher.GetInstance (out watcher, true);
|
||||
watcher_handle = this;
|
||||
break;
|
||||
case 5: // inotify
|
||||
ok = InotifyWatcher.GetInstance (out watcher, true);
|
||||
watcher_handle = this;
|
||||
break;
|
||||
case 6: // CoreFX
|
||||
ok = CoreFXFileSystemWatcherProxy.GetInstance (out watcher);
|
||||
watcher_handle = (watcher as CoreFXFileSystemWatcherProxy).NewWatcher (this);
|
||||
break;
|
||||
}
|
||||
|
||||
if (mode == 0 || !ok) {
|
||||
if (String.Compare (managed, "disabled", true) == 0)
|
||||
NullFileWatcher.GetInstance (out watcher);
|
||||
else
|
||||
else {
|
||||
DefaultWatcher.GetInstance (out watcher);
|
||||
watcher_handle = this;
|
||||
}
|
||||
}
|
||||
this.inited = true;
|
||||
|
||||
ShowWatcherInfo ();
|
||||
}
|
||||
@@ -173,9 +189,6 @@ namespace System.IO {
|
||||
return mangledFilter;
|
||||
|
||||
string filterLocal = "*.*";
|
||||
if (!(watcher.GetType () == typeof (WindowsWatcher)))
|
||||
filterLocal = "*";
|
||||
|
||||
return filterLocal;
|
||||
}
|
||||
}
|
||||
@@ -183,7 +196,7 @@ namespace System.IO {
|
||||
internal SearchPattern2 Pattern {
|
||||
get {
|
||||
if (pattern == null) {
|
||||
if (watcher.GetType () == typeof (KeventWatcher))
|
||||
if (watcher?.GetType () == typeof (KeventWatcher))
|
||||
pattern = new SearchPattern2 (MangledFilter, true); //assume we want to ignore case (OS X)
|
||||
else
|
||||
pattern = new SearchPattern2 (MangledFilter);
|
||||
@@ -210,6 +223,12 @@ namespace System.IO {
|
||||
public bool EnableRaisingEvents {
|
||||
get { return enableRaisingEvents; }
|
||||
set {
|
||||
if (disposed)
|
||||
throw new ObjectDisposedException (GetType().Name);
|
||||
|
||||
start_requested = true;
|
||||
if (!inited)
|
||||
return;
|
||||
if (value == enableRaisingEvents)
|
||||
return; // Do nothing
|
||||
|
||||
@@ -218,6 +237,7 @@ namespace System.IO {
|
||||
Start ();
|
||||
} else {
|
||||
Stop ();
|
||||
start_requested = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -232,7 +252,7 @@ namespace System.IO {
|
||||
if (value == null || value == "")
|
||||
value = "*.*";
|
||||
|
||||
if (filter != value) {
|
||||
if (!string.Equals(filter, value, PathInternal.StringComparison)) {
|
||||
filter = value;
|
||||
pattern = null;
|
||||
mangledFilter = null;
|
||||
@@ -264,8 +284,8 @@ namespace System.IO {
|
||||
if (internalBufferSize == value)
|
||||
return;
|
||||
|
||||
if (value < 4196)
|
||||
value = 4196;
|
||||
if (value < 4096)
|
||||
value = 4096;
|
||||
|
||||
internalBufferSize = value;
|
||||
if (enableRaisingEvents) {
|
||||
@@ -299,7 +319,11 @@ namespace System.IO {
|
||||
public string Path {
|
||||
get { return path; }
|
||||
set {
|
||||
if (path == value)
|
||||
if (disposed)
|
||||
throw new ObjectDisposedException (GetType().Name);
|
||||
|
||||
value = (value == null) ? string.Empty : value;
|
||||
if (string.Equals(path, value, PathInternal.StringComparison))
|
||||
return;
|
||||
|
||||
bool exists = false;
|
||||
@@ -312,10 +336,10 @@ namespace System.IO {
|
||||
}
|
||||
|
||||
if (exc != null)
|
||||
throw new ArgumentException ("Invalid directory name", "value", exc);
|
||||
throw new ArgumentException(SR.Format(SR.InvalidDirName, value), nameof(Path));
|
||||
|
||||
if (!exists)
|
||||
throw new ArgumentException ("Directory does not exist", "value");
|
||||
throw new ArgumentException(SR.Format(SR.InvalidDirName_NotExists, value), nameof(Path));
|
||||
|
||||
path = value;
|
||||
fullpath = null;
|
||||
@@ -329,7 +353,12 @@ namespace System.IO {
|
||||
[Browsable(false)]
|
||||
public override ISite Site {
|
||||
get { return base.Site; }
|
||||
set { base.Site = value; }
|
||||
set
|
||||
{
|
||||
base.Site = value;
|
||||
if (Site != null && Site.DesignMode)
|
||||
this.EnableRaisingEvents = true;
|
||||
}
|
||||
}
|
||||
|
||||
[DefaultValue(null)]
|
||||
@@ -347,27 +376,41 @@ namespace System.IO {
|
||||
public void BeginInit ()
|
||||
{
|
||||
// Not necessary in Mono
|
||||
// but if called, EndInit() must be called
|
||||
inited = false;
|
||||
}
|
||||
|
||||
protected override void Dispose (bool disposing)
|
||||
{
|
||||
if (!disposed) {
|
||||
disposed = true;
|
||||
Stop ();
|
||||
}
|
||||
if (disposed)
|
||||
return;
|
||||
|
||||
try {
|
||||
watcher?.StopDispatching (watcher_handle);
|
||||
watcher?.Dispose (watcher_handle);
|
||||
} catch (Exception) { }
|
||||
|
||||
watcher_handle = null;
|
||||
watcher = null;
|
||||
|
||||
disposed = true;
|
||||
base.Dispose (disposing);
|
||||
GC.SuppressFinalize (this);
|
||||
}
|
||||
|
||||
~FileSystemWatcher ()
|
||||
{
|
||||
disposed = true;
|
||||
Stop ();
|
||||
if (disposed)
|
||||
return;
|
||||
|
||||
Dispose (false);
|
||||
}
|
||||
|
||||
public void EndInit ()
|
||||
{
|
||||
// Not necessary in Mono
|
||||
inited = true;
|
||||
if (start_requested)
|
||||
this.EnableRaisingEvents = true;
|
||||
}
|
||||
|
||||
enum EventType {
|
||||
@@ -384,13 +427,13 @@ namespace System.IO {
|
||||
foreach (var target in ev.GetInvocationList()) {
|
||||
switch (evtype) {
|
||||
case EventType.RenameEvent:
|
||||
((RenamedEventHandler)target).BeginInvoke (this, (RenamedEventArgs)arg, null, null);
|
||||
((RenamedEventHandler)target).Invoke (this, (RenamedEventArgs)arg);
|
||||
break;
|
||||
case EventType.ErrorEvent:
|
||||
((ErrorEventHandler)target).BeginInvoke (this, (ErrorEventArgs)arg, null, null);
|
||||
((ErrorEventHandler)target).Invoke (this, (ErrorEventArgs)arg);
|
||||
break;
|
||||
case EventType.FileSystemEvent:
|
||||
((FileSystemEventHandler)target).BeginInvoke (this, (FileSystemEventArgs)arg, null, null);
|
||||
((FileSystemEventHandler)target).Invoke (this, (FileSystemEventArgs)arg);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -503,12 +546,20 @@ namespace System.IO {
|
||||
|
||||
void Start ()
|
||||
{
|
||||
watcher.StartDispatching (this);
|
||||
if (disposed)
|
||||
return;
|
||||
if (watcher_handle == null)
|
||||
return;
|
||||
watcher?.StartDispatching (watcher_handle);
|
||||
}
|
||||
|
||||
void Stop ()
|
||||
{
|
||||
watcher.StopDispatching (this);
|
||||
if (disposed)
|
||||
return;
|
||||
if (watcher_handle == null)
|
||||
return;
|
||||
watcher?.StopDispatching (watcher_handle);
|
||||
}
|
||||
#endregion // Methods
|
||||
|
||||
@@ -537,6 +588,7 @@ namespace System.IO {
|
||||
/* 3 -> Kevent */
|
||||
/* 4 -> gamin */
|
||||
/* 5 -> inotify */
|
||||
/* 6 -> CoreFX */
|
||||
[MethodImplAttribute(MethodImplOptions.InternalCall)]
|
||||
static extern int InternalSupportsFSW ();
|
||||
}
|
||||
|
@@ -1,64 +0,0 @@
|
||||
//
|
||||
// FileSystemWatcher.cs
|
||||
//
|
||||
// Authors:
|
||||
// Marek Safar <marek.safar@gmail.com>
|
||||
//
|
||||
// Copyright (C) 2016 Xamarin Inc (http://www.xamarin.com)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
using System.ComponentModel;
|
||||
|
||||
#pragma warning disable 67
|
||||
|
||||
namespace System.IO
|
||||
{
|
||||
public class FileSystemWatcher : Component, IDisposable, ISupportInitialize
|
||||
{
|
||||
public FileSystemWatcher () { throw new NotImplementedException (); }
|
||||
public FileSystemWatcher (string path) { throw new NotImplementedException (); }
|
||||
public FileSystemWatcher (string path, string filter) { throw new NotImplementedException (); }
|
||||
public bool EnableRaisingEvents { get { throw new NotImplementedException (); } set { throw new NotImplementedException (); } }
|
||||
public string Filter { get { throw new NotImplementedException (); } set { } }
|
||||
public bool IncludeSubdirectories { get { throw new NotImplementedException (); } set { } }
|
||||
public int InternalBufferSize { get { throw new NotImplementedException (); } set { } }
|
||||
public NotifyFilters NotifyFilter { get { throw new NotImplementedException (); } set { } }
|
||||
public string Path { get { throw new NotImplementedException (); } set { } }
|
||||
public override ISite Site { get { throw new NotImplementedException (); } set { } }
|
||||
public ISynchronizeInvoke SynchronizingObject { get { throw new NotImplementedException (); } set { } }
|
||||
public event FileSystemEventHandler Changed;
|
||||
public event FileSystemEventHandler Created;
|
||||
public event FileSystemEventHandler Deleted;
|
||||
public event ErrorEventHandler Error;
|
||||
public event RenamedEventHandler Renamed;
|
||||
public void BeginInit() { throw new NotImplementedException (); }
|
||||
public void EndInit() { throw new NotImplementedException (); }
|
||||
protected void OnChanged (FileSystemEventArgs e) { throw new NotImplementedException (); }
|
||||
protected void OnCreated (FileSystemEventArgs e) { throw new NotImplementedException (); }
|
||||
protected void OnDeleted (System.IO.FileSystemEventArgs e) { throw new NotImplementedException (); }
|
||||
protected void OnError (ErrorEventArgs e) { throw new NotImplementedException (); }
|
||||
protected void OnRenamed (RenamedEventArgs e) { throw new NotImplementedException (); }
|
||||
public WaitForChangedResult WaitForChanged (WatcherChangeTypes changeType) { throw new NotImplementedException (); }
|
||||
public WaitForChangedResult WaitForChanged (WatcherChangeTypes changeType, int timeout) { throw new NotImplementedException (); }
|
||||
protected override void Dispose (bool disposing) { }
|
||||
}
|
||||
}
|
@@ -30,8 +30,9 @@
|
||||
|
||||
namespace System.IO {
|
||||
interface IFileWatcher {
|
||||
void StartDispatching (FileSystemWatcher fsw);
|
||||
void StopDispatching (FileSystemWatcher fsw);
|
||||
void StartDispatching (object fsw);
|
||||
void StopDispatching (object fsw);
|
||||
void Dispose (object fsw);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -133,8 +133,11 @@ namespace System.IO {
|
||||
return true;
|
||||
}
|
||||
|
||||
public void StartDispatching (FileSystemWatcher fsw)
|
||||
public void StartDispatching (object handle)
|
||||
{
|
||||
if (handle == null)
|
||||
return;
|
||||
var fsw = handle as FileSystemWatcher;
|
||||
ParentInotifyData parent;
|
||||
lock (this) {
|
||||
if ((long) FD == -1)
|
||||
@@ -328,8 +331,11 @@ namespace System.IO {
|
||||
}
|
||||
}
|
||||
|
||||
public void StopDispatching (FileSystemWatcher fsw)
|
||||
public void StopDispatching (object handle)
|
||||
{
|
||||
if (handle == null)
|
||||
return;
|
||||
var fsw = handle as FileSystemWatcher;
|
||||
ParentInotifyData parent;
|
||||
lock (this) {
|
||||
parent = (ParentInotifyData) watches [fsw];
|
||||
@@ -608,6 +614,11 @@ namespace System.IO {
|
||||
return AddWatch (fd, directory, mask);
|
||||
}
|
||||
|
||||
public void Dispose (object handle)
|
||||
{
|
||||
// does nothing
|
||||
}
|
||||
|
||||
[DllImport ("libc", EntryPoint="close")]
|
||||
internal extern static int Close (IntPtr fd);
|
||||
|
||||
|
@@ -736,8 +736,9 @@ namespace System.IO {
|
||||
return true;
|
||||
}
|
||||
|
||||
public void StartDispatching (FileSystemWatcher fsw)
|
||||
public void StartDispatching (object handle)
|
||||
{
|
||||
var fsw = handle as FileSystemWatcher;
|
||||
KqueueMonitor monitor;
|
||||
|
||||
if (watches.ContainsKey (fsw)) {
|
||||
@@ -750,14 +751,20 @@ namespace System.IO {
|
||||
monitor.Start ();
|
||||
}
|
||||
|
||||
public void StopDispatching (FileSystemWatcher fsw)
|
||||
public void StopDispatching (object handle)
|
||||
{
|
||||
var fsw = handle as FileSystemWatcher;
|
||||
KqueueMonitor monitor = (KqueueMonitor)watches [fsw];
|
||||
if (monitor == null)
|
||||
return;
|
||||
|
||||
monitor.Stop ();
|
||||
}
|
||||
|
||||
public void Dispose (object handle)
|
||||
{
|
||||
// does nothing
|
||||
}
|
||||
|
||||
[DllImport ("libc")]
|
||||
extern static int close (int fd);
|
||||
|
@@ -35,12 +35,17 @@ namespace System.IO
|
||||
{
|
||||
static IFileWatcher instance;
|
||||
|
||||
public void StartDispatching (FileSystemWatcher fsw)
|
||||
public void StartDispatching (object handle)
|
||||
{
|
||||
// does nothing
|
||||
}
|
||||
|
||||
public void StopDispatching (FileSystemWatcher fsw)
|
||||
public void StopDispatching (object handle)
|
||||
{
|
||||
// does nothing
|
||||
}
|
||||
|
||||
public void Dispose (object handle)
|
||||
{
|
||||
// does nothing
|
||||
}
|
||||
|
@@ -1,69 +0,0 @@
|
||||
//
|
||||
// System.IO.WaitForChangedResult.cs
|
||||
//
|
||||
// Author:
|
||||
// Tim Coleman (tim@timcoleman.com)
|
||||
//
|
||||
// Copyright (C) Tim Coleman, 2002
|
||||
//
|
||||
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
using System;
|
||||
|
||||
namespace System.IO {
|
||||
public struct WaitForChangedResult {
|
||||
|
||||
#region Fields
|
||||
|
||||
WatcherChangeTypes changeType;
|
||||
string name;
|
||||
string oldName;
|
||||
bool timedOut;
|
||||
|
||||
#endregion // Fields
|
||||
|
||||
#region Properties
|
||||
|
||||
public WatcherChangeTypes ChangeType {
|
||||
get { return changeType; }
|
||||
set { changeType = value; }
|
||||
}
|
||||
|
||||
public string Name {
|
||||
get { return name; }
|
||||
set { name = value; }
|
||||
}
|
||||
|
||||
public string OldName {
|
||||
get { return oldName; }
|
||||
set { oldName = value; }
|
||||
}
|
||||
|
||||
public bool TimedOut {
|
||||
get { return timedOut; }
|
||||
set { timedOut = value; }
|
||||
}
|
||||
|
||||
#endregion // Properties
|
||||
}
|
||||
}
|
@@ -1,53 +0,0 @@
|
||||
//
|
||||
// System.IO.WindowsWatcher.cs: windows IFileWatcher
|
||||
//
|
||||
// Authors:
|
||||
// Gonzalo Paniagua Javier (gonzalo@ximian.com)
|
||||
//
|
||||
// (c) 2004 Novell, Inc. (http://www.novell.com)
|
||||
//
|
||||
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
namespace System.IO {
|
||||
class WindowsWatcher : IFileWatcher
|
||||
{
|
||||
private WindowsWatcher ()
|
||||
{
|
||||
}
|
||||
|
||||
// Locked by caller
|
||||
public static bool GetInstance (out IFileWatcher watcher)
|
||||
{
|
||||
throw new NotSupportedException ();
|
||||
}
|
||||
|
||||
public void StartDispatching (FileSystemWatcher fsw)
|
||||
{
|
||||
}
|
||||
|
||||
public void StopDispatching (FileSystemWatcher fsw)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -613,6 +613,9 @@ namespace System.Net.NetworkInformation {
|
||||
[DllImport ("iphlpapi.dll")]
|
||||
static extern int GetIpStatisticsEx (out Win32_MIB_IPSTATS pStats, int dwFamily);
|
||||
|
||||
[DllImport ("Ws2_32.dll")]
|
||||
static extern ushort ntohs (ushort netshort);
|
||||
|
||||
// Win32 structures
|
||||
|
||||
[StructLayout (LayoutKind.Explicit)]
|
||||
@@ -673,10 +676,10 @@ namespace System.Net.NetworkInformation {
|
||||
class Win32_MIB_UDPROW
|
||||
{
|
||||
public uint LocalAddr;
|
||||
public int LocalPort;
|
||||
public uint LocalPort;
|
||||
|
||||
public IPEndPoint LocalEndPoint {
|
||||
get { return new IPEndPoint (LocalAddr, LocalPort); }
|
||||
get { return new IPEndPoint (LocalAddr, ntohs((ushort)LocalPort)); }
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -1,162 +0,0 @@
|
||||
//
|
||||
// System.Net.FtpAsyncResult.cs
|
||||
//
|
||||
// Authors:
|
||||
// Carlos Alberto Cortez (calberto.cortez@gmail.com)
|
||||
//
|
||||
// (c) Copyright 2006 Novell, Inc. (http://www.novell.com)
|
||||
//
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Net;
|
||||
|
||||
namespace System.Net
|
||||
{
|
||||
class FtpAsyncResult : IAsyncResult
|
||||
{
|
||||
FtpWebResponse response;
|
||||
ManualResetEvent waitHandle;
|
||||
Exception exception;
|
||||
AsyncCallback callback;
|
||||
Stream stream;
|
||||
object state;
|
||||
bool completed;
|
||||
bool synch;
|
||||
object locker = new object ();
|
||||
|
||||
public FtpAsyncResult (AsyncCallback callback, object state)
|
||||
{
|
||||
this.callback = callback;
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
public object AsyncState {
|
||||
get {
|
||||
return state;
|
||||
}
|
||||
}
|
||||
|
||||
public WaitHandle AsyncWaitHandle {
|
||||
get {
|
||||
lock (locker) {
|
||||
if (waitHandle == null)
|
||||
waitHandle = new ManualResetEvent (false);
|
||||
}
|
||||
|
||||
return waitHandle;
|
||||
}
|
||||
}
|
||||
|
||||
public bool CompletedSynchronously {
|
||||
get {
|
||||
return synch;
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsCompleted {
|
||||
get {
|
||||
lock (locker) {
|
||||
return completed;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal bool GotException {
|
||||
get {
|
||||
return exception != null;
|
||||
}
|
||||
}
|
||||
|
||||
internal Exception Exception {
|
||||
get {
|
||||
return exception;
|
||||
}
|
||||
}
|
||||
|
||||
internal FtpWebResponse Response {
|
||||
get {
|
||||
return response;
|
||||
}
|
||||
set {
|
||||
response = value;
|
||||
}
|
||||
}
|
||||
|
||||
internal Stream Stream {
|
||||
get {
|
||||
return stream;
|
||||
}
|
||||
|
||||
set { stream = value; }
|
||||
}
|
||||
|
||||
internal void WaitUntilComplete ()
|
||||
{
|
||||
if (IsCompleted)
|
||||
return;
|
||||
|
||||
AsyncWaitHandle.WaitOne ();
|
||||
}
|
||||
|
||||
internal bool WaitUntilComplete (int timeout, bool exitContext)
|
||||
{
|
||||
if (IsCompleted)
|
||||
return true;
|
||||
|
||||
return AsyncWaitHandle.WaitOne (timeout, exitContext);
|
||||
}
|
||||
|
||||
internal void SetCompleted (bool synch, Exception exc, FtpWebResponse response)
|
||||
{
|
||||
this.synch = synch;
|
||||
this.exception = exc;
|
||||
this.response = response;
|
||||
lock (locker) {
|
||||
completed = true;
|
||||
if (waitHandle != null)
|
||||
waitHandle.Set ();
|
||||
}
|
||||
DoCallback ();
|
||||
}
|
||||
|
||||
internal void SetCompleted (bool synch, FtpWebResponse response)
|
||||
{
|
||||
SetCompleted (synch, null, response);
|
||||
}
|
||||
|
||||
internal void SetCompleted (bool synch, Exception exc)
|
||||
{
|
||||
SetCompleted (synch, exc, null);
|
||||
}
|
||||
|
||||
internal void DoCallback ()
|
||||
{
|
||||
if (callback != null)
|
||||
try {
|
||||
callback (this);
|
||||
}
|
||||
catch (Exception) {
|
||||
}
|
||||
}
|
||||
|
||||
// Cleanup resources
|
||||
internal void Reset ()
|
||||
{
|
||||
exception = null;
|
||||
synch = false;
|
||||
response = null;
|
||||
state = null;
|
||||
|
||||
lock (locker) {
|
||||
completed = false;
|
||||
if (waitHandle != null)
|
||||
waitHandle.Reset ();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -1,252 +0,0 @@
|
||||
//
|
||||
// System.Net.FtpDataStream.cs
|
||||
//
|
||||
// Authors:
|
||||
// Carlos Alberto Cortez (calberto.cortez@gmail.com)
|
||||
//
|
||||
// (c) Copyright 2006 Novell, Inc. (http://www.novell.com)
|
||||
//
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Net.Sockets;
|
||||
using System.Runtime.Remoting.Messaging;
|
||||
using System.Threading;
|
||||
using System.Net;
|
||||
|
||||
namespace System.Net
|
||||
{
|
||||
class FtpDataStream : Stream, IDisposable
|
||||
{
|
||||
FtpWebRequest request;
|
||||
Stream networkStream;
|
||||
bool disposed;
|
||||
bool isRead;
|
||||
int totalRead;
|
||||
|
||||
internal FtpDataStream (FtpWebRequest request, Stream stream, bool isRead)
|
||||
{
|
||||
if (request == null)
|
||||
throw new ArgumentNullException ("request");
|
||||
|
||||
this.request = request;
|
||||
this.networkStream = stream;
|
||||
this.isRead = isRead;
|
||||
}
|
||||
|
||||
public override bool CanRead {
|
||||
get {
|
||||
return isRead;
|
||||
}
|
||||
}
|
||||
|
||||
public override bool CanWrite {
|
||||
get {
|
||||
return !isRead;
|
||||
}
|
||||
}
|
||||
|
||||
public override bool CanSeek {
|
||||
get {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public override long Length {
|
||||
get {
|
||||
throw new NotSupportedException ();
|
||||
}
|
||||
}
|
||||
|
||||
public override long Position {
|
||||
get {
|
||||
throw new NotSupportedException ();
|
||||
}
|
||||
set {
|
||||
throw new NotSupportedException ();
|
||||
}
|
||||
}
|
||||
|
||||
internal Stream NetworkStream {
|
||||
get {
|
||||
CheckDisposed ();
|
||||
return networkStream;
|
||||
}
|
||||
}
|
||||
|
||||
public override void Close ()
|
||||
{
|
||||
Dispose (true);
|
||||
}
|
||||
|
||||
public override void Flush ()
|
||||
{
|
||||
// Do nothing.
|
||||
}
|
||||
|
||||
public override long Seek (long offset, SeekOrigin origin)
|
||||
{
|
||||
throw new NotSupportedException ();
|
||||
}
|
||||
|
||||
public override void SetLength (long value)
|
||||
{
|
||||
throw new NotSupportedException ();
|
||||
}
|
||||
|
||||
int ReadInternal (byte [] buffer, int offset, int size)
|
||||
{
|
||||
int nbytes = 0;
|
||||
request.CheckIfAborted ();
|
||||
|
||||
try {
|
||||
// Probably it would be better to have the socket here
|
||||
nbytes = networkStream.Read (buffer, offset, size);
|
||||
} catch (IOException) {
|
||||
throw new ProtocolViolationException ("Server commited a protocol violation");
|
||||
}
|
||||
|
||||
totalRead += nbytes;
|
||||
if (nbytes == 0) {
|
||||
networkStream = null;
|
||||
request.CloseDataConnection ();
|
||||
request.SetTransferCompleted ();
|
||||
}
|
||||
|
||||
return nbytes;
|
||||
}
|
||||
|
||||
public override IAsyncResult BeginRead (byte [] buffer, int offset, int size, AsyncCallback cb, object state)
|
||||
{
|
||||
CheckDisposed ();
|
||||
|
||||
if (!isRead)
|
||||
throw new NotSupportedException ();
|
||||
if (buffer == null)
|
||||
throw new ArgumentNullException ("buffer");
|
||||
if (offset < 0 || offset > buffer.Length)
|
||||
throw new ArgumentOutOfRangeException ("offset");
|
||||
if (size < 0 || size > buffer.Length - offset)
|
||||
throw new ArgumentOutOfRangeException ("offset+size");
|
||||
|
||||
ReadDelegate del = ReadInternal;
|
||||
return del.BeginInvoke (buffer, offset, size, cb, state);
|
||||
}
|
||||
|
||||
public override int EndRead (IAsyncResult asyncResult)
|
||||
{
|
||||
if (asyncResult == null)
|
||||
throw new ArgumentNullException ("asyncResult");
|
||||
|
||||
AsyncResult ar = asyncResult as AsyncResult;
|
||||
if (ar == null)
|
||||
throw new ArgumentException ("Invalid asyncResult", "asyncResult");
|
||||
|
||||
ReadDelegate del = ar.AsyncDelegate as ReadDelegate;
|
||||
if (del == null)
|
||||
throw new ArgumentException ("Invalid asyncResult", "asyncResult");
|
||||
|
||||
return del.EndInvoke (asyncResult);
|
||||
}
|
||||
|
||||
public override int Read (byte [] buffer, int offset, int size)
|
||||
{
|
||||
request.CheckIfAborted ();
|
||||
IAsyncResult ar = BeginRead (buffer, offset, size, null, null);
|
||||
if (!ar.IsCompleted && !ar.AsyncWaitHandle.WaitOne (request.ReadWriteTimeout, false))
|
||||
throw new WebException ("Read timed out.", WebExceptionStatus.Timeout);
|
||||
return EndRead (ar);
|
||||
}
|
||||
|
||||
|
||||
delegate void WriteDelegate (byte [] buffer, int offset, int size);
|
||||
|
||||
void WriteInternal (byte [] buffer, int offset, int size)
|
||||
{
|
||||
request.CheckIfAborted ();
|
||||
|
||||
try {
|
||||
networkStream.Write (buffer, offset, size);
|
||||
} catch (IOException) {
|
||||
throw new ProtocolViolationException ();
|
||||
}
|
||||
}
|
||||
|
||||
public override IAsyncResult BeginWrite (byte [] buffer, int offset, int size, AsyncCallback cb, object state)
|
||||
{
|
||||
CheckDisposed ();
|
||||
if (isRead)
|
||||
throw new NotSupportedException ();
|
||||
if (buffer == null)
|
||||
throw new ArgumentNullException ("buffer");
|
||||
if (offset < 0 || offset > buffer.Length)
|
||||
throw new ArgumentOutOfRangeException ("offset");
|
||||
if (size < 0 || size > buffer.Length - offset)
|
||||
throw new ArgumentOutOfRangeException ("offset+size");
|
||||
|
||||
WriteDelegate del = WriteInternal;
|
||||
return del.BeginInvoke (buffer, offset, size, cb, state);
|
||||
}
|
||||
|
||||
public override void EndWrite (IAsyncResult asyncResult)
|
||||
{
|
||||
if (asyncResult == null)
|
||||
throw new ArgumentNullException ("asyncResult");
|
||||
|
||||
AsyncResult ar = asyncResult as AsyncResult;
|
||||
if (ar == null)
|
||||
throw new ArgumentException ("Invalid asyncResult.", "asyncResult");
|
||||
|
||||
WriteDelegate del = ar.AsyncDelegate as WriteDelegate;
|
||||
if (del == null)
|
||||
throw new ArgumentException ("Invalid asyncResult.", "asyncResult");
|
||||
|
||||
del.EndInvoke (asyncResult);
|
||||
}
|
||||
|
||||
public override void Write (byte [] buffer, int offset, int size)
|
||||
{
|
||||
request.CheckIfAborted ();
|
||||
IAsyncResult ar = BeginWrite (buffer, offset, size, null, null);
|
||||
if (!ar.IsCompleted && !ar.AsyncWaitHandle.WaitOne (request.ReadWriteTimeout, false))
|
||||
throw new WebException ("Read timed out.", WebExceptionStatus.Timeout);
|
||||
|
||||
EndWrite (ar);
|
||||
}
|
||||
|
||||
~FtpDataStream ()
|
||||
{
|
||||
Dispose (false);
|
||||
}
|
||||
|
||||
void IDisposable.Dispose ()
|
||||
{
|
||||
Dispose (true);
|
||||
GC.SuppressFinalize (this);
|
||||
}
|
||||
|
||||
protected override void Dispose (bool disposing)
|
||||
{
|
||||
if (disposed)
|
||||
return;
|
||||
|
||||
disposed = true;
|
||||
if (networkStream != null) {
|
||||
request.CloseDataConnection ();
|
||||
request.SetTransferCompleted ();
|
||||
request = null;
|
||||
networkStream = null;
|
||||
}
|
||||
}
|
||||
|
||||
void CheckDisposed ()
|
||||
{
|
||||
if (disposed)
|
||||
throw new ObjectDisposedException (GetType ().FullName);
|
||||
}
|
||||
|
||||
delegate int ReadDelegate (byte [] buffer, int offset, int size);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -1,43 +0,0 @@
|
||||
//
|
||||
// System.Net.FtpbRequestCreator.cs
|
||||
//
|
||||
// Authors:
|
||||
// Carlos Alberto Cortez (calberto.cortez@gmail.com)
|
||||
//
|
||||
// (c) Copyright 2006 Novell, Inc. (http://www.novell.com)
|
||||
//
|
||||
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
namespace System.Net
|
||||
{
|
||||
class FtpRequestCreator : IWebRequestCreate
|
||||
{
|
||||
public WebRequest Create (Uri uri)
|
||||
{
|
||||
return new FtpWebRequest (uri);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -28,9 +28,9 @@
|
||||
|
||||
namespace System.Net
|
||||
{
|
||||
class FtpRequestCreator : IWebRequestCreate
|
||||
class FtpWebRequestCreator : IWebRequestCreate
|
||||
{
|
||||
internal const string EXCEPTION_MESSAGE = "System.Net.FtpRequestCreator is not supported on the current platform.";
|
||||
internal const string EXCEPTION_MESSAGE = "System.Net.FtpWebRequestCreator is not supported on the current platform.";
|
||||
public WebRequest Create (Uri uri)
|
||||
{
|
||||
throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
|
||||
|
@@ -1,51 +0,0 @@
|
||||
// System.Net.FtpStatus.cs
|
||||
//
|
||||
// Authors:
|
||||
// David Elkind (davide@mainsoft.com)
|
||||
//
|
||||
// Copyright (C) 2006 Mainsoft Corp.
|
||||
// http://www.mainsoft.com
|
||||
//
|
||||
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
namespace System.Net
|
||||
{
|
||||
internal class FtpStatus
|
||||
{
|
||||
readonly FtpStatusCode statusCode;
|
||||
readonly string statusDescription;
|
||||
|
||||
public FtpStatus (FtpStatusCode statusCode, string statusDescription) {
|
||||
this.statusCode = statusCode;
|
||||
this.statusDescription = statusDescription;
|
||||
}
|
||||
|
||||
public FtpStatusCode StatusCode {
|
||||
get { return statusCode; }
|
||||
}
|
||||
|
||||
public string StatusDescription {
|
||||
get { return statusDescription; }
|
||||
}
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@@ -1,184 +0,0 @@
|
||||
//
|
||||
// System.Net.FtpWebResponse.cs
|
||||
//
|
||||
// Authors:
|
||||
// Carlos Alberto Cortez (calberto.cortez@gmail.com)
|
||||
//
|
||||
// (c) Copyright 2006 Novell, Inc. (http://www.novell.com)
|
||||
//
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Net;
|
||||
|
||||
namespace System.Net
|
||||
{
|
||||
public class FtpWebResponse : WebResponse
|
||||
{
|
||||
Stream stream;
|
||||
Uri uri;
|
||||
FtpStatusCode statusCode;
|
||||
DateTime lastModified = DateTime.MinValue;
|
||||
string bannerMessage = String.Empty;
|
||||
string welcomeMessage = String.Empty;
|
||||
string exitMessage = String.Empty;
|
||||
string statusDescription;
|
||||
string method;
|
||||
//bool keepAlive;
|
||||
bool disposed;
|
||||
FtpWebRequest request;
|
||||
internal long contentLength = -1;
|
||||
|
||||
internal FtpWebResponse (FtpWebRequest request, Uri uri, string method, bool keepAlive)
|
||||
{
|
||||
this.request = request;
|
||||
this.uri = uri;
|
||||
this.method = method;
|
||||
//this.keepAlive = keepAlive;
|
||||
}
|
||||
|
||||
internal FtpWebResponse (FtpWebRequest request, Uri uri, string method, FtpStatusCode statusCode, string statusDescription)
|
||||
{
|
||||
this.request = request;
|
||||
this.uri = uri;
|
||||
this.method = method;
|
||||
this.statusCode = statusCode;
|
||||
this.statusDescription = statusDescription;
|
||||
}
|
||||
|
||||
internal FtpWebResponse (FtpWebRequest request, Uri uri, string method, FtpStatus status) :
|
||||
this (request, uri, method, status.StatusCode, status.StatusDescription)
|
||||
{
|
||||
}
|
||||
|
||||
public override long ContentLength {
|
||||
get {
|
||||
return contentLength;
|
||||
}
|
||||
}
|
||||
|
||||
public override WebHeaderCollection Headers {
|
||||
get {
|
||||
return new WebHeaderCollection ();
|
||||
}
|
||||
}
|
||||
|
||||
public override Uri ResponseUri {
|
||||
get {
|
||||
return uri;
|
||||
}
|
||||
}
|
||||
|
||||
public DateTime LastModified {
|
||||
get {
|
||||
return lastModified;
|
||||
}
|
||||
internal set {
|
||||
lastModified = value;
|
||||
}
|
||||
}
|
||||
|
||||
public string BannerMessage {
|
||||
get {
|
||||
return bannerMessage;
|
||||
}
|
||||
internal set {
|
||||
bannerMessage = value;
|
||||
}
|
||||
}
|
||||
|
||||
public string WelcomeMessage {
|
||||
get {
|
||||
return welcomeMessage;
|
||||
}
|
||||
internal set {
|
||||
welcomeMessage = value;
|
||||
}
|
||||
}
|
||||
|
||||
public string ExitMessage {
|
||||
get {
|
||||
return exitMessage;
|
||||
}
|
||||
internal set {
|
||||
exitMessage = value;
|
||||
}
|
||||
}
|
||||
|
||||
public FtpStatusCode StatusCode {
|
||||
get {
|
||||
return statusCode;
|
||||
}
|
||||
internal set {
|
||||
statusCode = value;
|
||||
}
|
||||
}
|
||||
|
||||
public override bool SupportsHeaders {
|
||||
get {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public string StatusDescription {
|
||||
get {
|
||||
return statusDescription;
|
||||
}
|
||||
internal set {
|
||||
statusDescription = value;
|
||||
}
|
||||
}
|
||||
|
||||
public override void Close ()
|
||||
{
|
||||
if (disposed)
|
||||
return;
|
||||
|
||||
disposed = true;
|
||||
if (stream != null) {
|
||||
stream.Close ();
|
||||
if (stream == Stream.Null)
|
||||
request.OperationCompleted ();
|
||||
}
|
||||
stream = null;
|
||||
}
|
||||
|
||||
public override Stream GetResponseStream ()
|
||||
{
|
||||
if (stream == null)
|
||||
return Stream.Null; // After a STOR we get this
|
||||
|
||||
if (method != WebRequestMethods.Ftp.DownloadFile &&
|
||||
method != WebRequestMethods.Ftp.ListDirectory)
|
||||
CheckDisposed ();
|
||||
|
||||
return stream;
|
||||
}
|
||||
|
||||
internal Stream Stream {
|
||||
set {
|
||||
stream = value;
|
||||
}
|
||||
|
||||
get { return stream; }
|
||||
}
|
||||
|
||||
internal void UpdateStatus (FtpStatus status) {
|
||||
statusCode = status.StatusCode;
|
||||
statusDescription = status.StatusDescription;
|
||||
}
|
||||
|
||||
void CheckDisposed ()
|
||||
{
|
||||
if (disposed)
|
||||
throw new ObjectDisposedException (GetType ().FullName);
|
||||
}
|
||||
|
||||
internal bool IsFinal () {
|
||||
return ((int) statusCode >= 200);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user