- Use readonly object as lock
Info from stackoverflow:
If I want to be sure that it will be locked for all threads inside my
application:
The lock object has to be static, if it locks access to static state.
Otherwise it has to be instance, because there's no need to lock state of
one class instance, and prevent other threads to work with another class
instance at the same time.
everyone says that the object has to be "readonly" I didn't found the
reason
Well, it doesn't have to be. This is just a best practice, which helps you
to avoid errors.
Signed-off-by: Syrone Wong <wong.syrone@gmail.com>
after creation.
Becuase we put handler.Start() call after timeout check and
lastActivity is initialized in Start(), this will lead to a
incorrect timeout.
Also because we will call handler.Start() right after the
constructor and timeout check, so it makes no difference
where we put the initializtion of lastActivity. We won't do
this again in Start() because DateTime.Now will consumes a
lot of cpu time.
When using http proxy, this will cause distinct latency
if we are trying to resolve localhost.
Currently it's unnecessary to do that because our privoxy
doesn't listern on ipv6 address, so it's ok to hard code
the ipv4 address.
There is a plan to add a cache to record the ipv6 connectivity
so that we needn't to try both ipv4 and ipv6 every time when we
attempt to connect a DnsEndPoint.
Lock is evil.
This will actually affect the accuracy of GetDelta because
inboundDelta and outboundDelta may be calculated based on
the data collected at different time (eg. UpdateOutbound
get called before Interlocked.Read(ref _outbound)).
But that's not a problem. We can tolerate this little
inaccuracy. Besides, the _inbound, _outbound, _lastInbound
and _lastOutbound will be totally good because we use Interlocked.
To prevent "The IAsyncResult object was not returned from
the corresponding asynchronous method on this class." exception.
Signed-off-by: noisyfox <timemanager.rick@gmail.com>
Socket.ConnectAsync will create socket and handle the address family
itself. This solves some compatibility issues on win7.
Signed-off-by: noisyfox <timemanager.rick@gmail.com>
Try to access a dead process's MainModule will cause
"A 32 bit processes cannot access modules of
a 64 bit process." exception on win7 x64.
Simply ignore it.
Signed-off-by: noisyfox <timemanager.rick@gmail.com>
* Use job object to manage polipo service's external processes.
Signed-off-by: noisyfox <timemanager.rick@gmail.com>
* Only kill those ss_privoxy.exe created by this ss instance.
Signed-off-by: noisyfox <timemanager.rick@gmail.com>
* Update README
Signed-off-by: noisyfox <timemanager.rick@gmail.com>
At that time the remote even doesn't exist.
Also this debug output doesn't make any sense because when handling
udp request, this tcp connection won't have any meaningful data.
So I simply removed these two lines.
Signed-off-by: noisyfox <timemanager.rick@gmail.com>
-Use dual-mode socket & DnsEndPoint to handle all domain name connection.
-Move all socket creation into one single function.
So that we could treat domain name just like ipv4 & ipv6 address.
This also solves the async domain solving problem because the os will
hanlde it for us.
- use null conditional access in case some connections been
cancelled unexpectedly and may cause null reference exception
- Refine error message
- use conditional operator to simplify some code
Signed-off-by: Syrone Wong <wong.syrone@gmail.com>