Commit Graph

43 Commits

Author SHA1 Message Date
Slava Egorov bbd407725e [vm/io,win] Remove Handle::EnsureInitialized
`Handle` objects which used by Windows specific implementation of
`EventHandler` have complicated life cycle and haphazard approach
to locking. This CL is the first in a series of CLs which attempts
to clean this up a bit - with a final goal to avoid recursively
locking `Handle::monitor_`.

In this CL we remove `Handle::EnsureInitialized` method which
was primarily responsible for associating `HANDLE` with
`EventHandler`'s completion port. Instead we move this logic
into `Handle` constructor.

We also cleanup reference counting logic applied to handles which
participate in asynchronous operations: instead of eagerly
incrementing reference count when `HANDLE` is associated with
the completion port we increment it whenever asynchronous operation
is in progress and decrement it when it completes. This makes the
code much simpler to reason about and avoids necessity to write
code like:

    handle->Release();
    handle->Release();

accompanied with comments explaining why we need to drop
two references due to eager increment.

Finally we cleanup the handling of provider-specific extensions
accessed through `WSAIoctl`'s `SIO_GET_EXTENSION_FUNCTION_POINTER`.
We were fetching them for every individual socket instead of
fetching them once and caching them globally.

TEST=ci

Cq-Include-Trybots: luci.dart.try:vm-win-debug-x64-try,pkg-win-release-try,analyzer-win-release-try,vm-win-release-x64-try
Change-Id: Ia8b391b713b1a1afb9df9e931eada6abf97f7854
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/378140
Reviewed-by: Martin Kustermann <kustermann@google.com>
2024-08-06 12:26:19 +00:00
Liam Appelbe ec599a5977 [VM] Remove retry logic from close(fd) calls
This covers Linux, Mac, Android, and Fuchsia.

Bug: https://github.com/dart-lang/sdk/issues/35954
Fixes: https://github.com/dart-lang/sdk/issues/35954
Change-Id: I8142332c530be8ad3ce46312a4a5ac750953c288
Reviewed-on: https://dart-review.googlesource.com/c/93320
Commit-Queue: Liam Appelbe <liama@google.com>
Reviewed-by: Siva Annamalai <asiva@google.com>
2019-02-15 23:28:17 +00:00
Zach Anderson 27c79f9459 [vm] Propagate more UTF8 conversion errors
Change-Id: I8d4f3a892a51bed8b922961bd74bcad727f66508
Reviewed-on: https://dart-review.googlesource.com/73280
Commit-Queue: Zach Anderson <zra@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Siva Annamalai <asiva@google.com>
2018-09-06 02:23:21 +00:00
Ryan Macnak 60a7160273 Reapply "[vm] Prevent non-fatal errors from causing timers to be dropped."
Fix Linux event handler to re-arm the timer_fd after handling a wakeup.

R=zra@google.com

Review-Url: https://codereview.chromium.org/2996243003 .
2017-08-18 13:38:08 -07:00
Zachary Anderson 6cd8a79078 VM: Re-format to use at most one newline between functions
R=asiva@google.com

Review-Url: https://codereview.chromium.org/2974233002 .
2017-07-13 08:08:37 -07:00
Zachary Anderson 479a97b129 clang-format runtime/bin
R=johnmccutchan@google.com

Review URL: https://codereview.chromium.org/2480793002 .
2016-11-04 12:30:56 -07:00
Zachary Anderson 103881d01c Make header include guards great again
i.e. #ifndef VM_WHATEVER -> #ifndef RUNTIME_VM_WHATEVER

This lets us remove a hack from the PRESUBMIT.py script that existed
for reasons that are no longer valid, and sets us up to add some
presubmit checks for the GN build.

R=asiva@google.com, rmacnak@google.com

Review URL: https://codereview.chromium.org/2450713004 .
2016-10-26 00:26:03 -07:00
Zachary Anderson 45661a7091 Cleanup in //runtime/bin
R=iposva@google.com

Review URL: https://codereview.chromium.org/1800863002 .
2016-03-16 10:01:00 -07:00
kustermann@google.com 74c0f65c89 Implement windows support for having multiple Dart_Port's registered on one OS socket
R=sgjesse@google.com

Review URL: https://codereview.chromium.org//910863003

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@43631 260f80e4-7a28-3924-810f-c04153c831b5
2015-02-10 10:08:49 +00:00
kustermann@google.com ebde0dbaeb Extract common Mask/Dart_Port settings of linux event handler implementation to eventhandler.h
R=sgjesse@google.com, wibling@google.com

Review URL: https://codereview.chromium.org//905733002

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@43585 260f80e4-7a28-3924-810f-c04153c831b5
2015-02-09 08:50:32 +00:00
kustermann@google.com a7f50cd5d2 Move CircularLinkedList to eventhandler.h
Move constants and InterruptMessage to eventhandler.h

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@43524 260f80e4-7a28-3924-810f-c04153c831b5
2015-02-05 21:45:47 +00:00
kustermann@google.com 1d6231bacd Revert "Introduce optional 'bool shared' parameter to ServerSocket.bind() ..."
Review URL: https://codereview.chromium.org//896213002

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@43476 260f80e4-7a28-3924-810f-c04153c831b5
2015-02-04 16:00:21 +00:00
kustermann@google.com 3c6c29fee9 Introduce optional 'bool shared' parameter to ServerSocket.bind() ...
R=sgjesse@google.com, wibling@google.com

Review URL: https://codereview.chromium.org//879353003

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@43467 260f80e4-7a28-3924-810f-c04153c831b5
2015-02-04 13:41:41 +00:00
kustermann@google.com 360dfe4f41 Several bugfixes in dart:io's handing of sockets
This CL includes fixes for the following issues:

a) The event handler created listening socket metadata (values of a hashtable
indexed by filedescriptor) sometimes as SocketData and sometimes as
ListeningSocketData depending whether the socket has been listened to or not.
This was very buggy, in particular because multiple isolates can have a
reference to the same server socket in different states (opened, listened,
closed).

=> This should be fixed by sending the file descriptior typeMask always to the
   eventhandler.

b) A server socket cloned via the ServerSocketReference mechanism, opens a
receive port for sending (fd, address, port) to isolates/... which want to
create a server socket from the reference.
This receive port was not closed properly when calling only close() (and not
listening first).

=> This should be fixed by closing this receiveport on the ServerSocket.close()
   call as well.

c) It was assumed in the event handler that a close command needs to have the
Dart_Port in a hash table. But this is only the case if the user actually
listened to the ServerSocket. Otherwise the event handler does not know about
the server socket. This caused a NULL dereference which resulted in a SEGFAULT.

=> This should be fixed by checking if the Dart_Port is in the hashmap of the
ListeningSocketData or not.

d) Too many bits were considered when extracting token count in C++ code.

The CL includes a regression test which should trigger these issues.

BUG=21384,21383
R=sgjesse@google.com

Review URL: https://codereview.chromium.org//665823007

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@41276 260f80e4-7a28-3924-810f-c04153c831b5
2014-10-24 08:55:50 +00:00
ajohnsen@google.com c7a15b7c2b Add support for cloning server-sockets.
BUG=
R=lrn@google.com, sgjesse@google.com

Review URL: https://codereview.chromium.org//250513002

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@35818 260f80e4-7a28-3924-810f-c04153c831b5
2014-05-06 19:09:44 +00:00
ajohnsen@google.com 1a8f76beb3 Only return eventhandler tokens in stacks of 8, to avoid runtime calls.
BUG=
R=sgjesse@google.com

Review URL: https://codereview.chromium.org//208653012

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@34359 260f80e4-7a28-3924-810f-c04153c831b5
2014-03-25 13:44:01 +00:00
ajohnsen@google.com 0c157cd31e Move signal_blocker to platform and use it by default in TEMP_FAILURE_RETRY.
BUG=http://code.google.com/p/dart/issues/detail?id=16927
R=johnmccutchan@google.com, sgjesse@google.com

Review URL: https://codereview.chromium.org//165723007

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@33745 260f80e4-7a28-3924-810f-c04153c831b5
2014-03-17 13:51:11 +00:00
ajohnsen@google.com 9a71498127 Make the event-handler handle backpreasure.
We now limit the number of active events per fd to 8.

BUG=
R=whesse@google.com

Review URL: https://codereview.chromium.org//198743002

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@33649 260f80e4-7a28-3924-810f-c04153c831b5
2014-03-13 12:02:47 +00:00
ajohnsen@google.com e3372e72e9 Remove SocketData and now only pass the dart port to epoll.
This avoids keeping extra data alive.

BUG=
R=sgjesse@google.com

Review URL: https://codereview.chromium.org//171503009

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@32846 260f80e4-7a28-3924-810f-c04153c831b5
2014-02-20 08:56:54 +00:00
ajohnsen@google.com 8f83775ead Fix build by removing unused class member.
BUG=

Review URL: https://codereview.chromium.org//172103005

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@32797 260f80e4-7a28-3924-810f-c04153c831b5
2014-02-19 16:49:27 +00:00
ajohnsen@google.com cabe710753 Remove 'mask' from SocketData, as it's not required.
BUG=
R=sgjesse@google.com

Review URL: https://codereview.chromium.org//167193004

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@32794 260f80e4-7a28-3924-810f-c04153c831b5
2014-02-19 16:15:00 +00:00
ajohnsen@google.com 140fddd06e Make event-handlers edge-triggered and move socket-state to Dart.
This eliminates to pause/resume calls made in the previous one-shot based model.

BUG=
R=sgjesse@google.com

Review URL: https://codereview.chromium.org//169383003

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@32780 260f80e4-7a28-3924-810f-c04153c831b5
2014-02-19 09:44:26 +00:00
ajohnsen@google.com 9a8edb6924 Use timerfd to handle timeouts on Linux.
BUG=
R=sgjesse@google.com

Review URL: https://codereview.chromium.org//104803005

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@30884 260f80e4-7a28-3924-810f-c04153c831b5
2013-12-05 09:22:07 +00:00
ajohnsen@google.com ff5f4fbdc9 Only read from interrupt_fd when data is available.
BUG=
R=sgjesse@google.com

Review URL: https://codereview.chromium.org//77983002

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@30453 260f80e4-7a28-3924-810f-c04153c831b5
2013-11-20 10:26:59 +00:00
ajohnsen@google.com 1e2289e275 One event ahndler for all isolates
BUG=
R=whesse@google.com

Review URL: https://codereview.chromium.org//17851004

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@25082 260f80e4-7a28-3924-810f-c04153c831b5
2013-07-17 07:26:05 +00:00
sgjesse@google.com 89a21f2479 Change the timeout handling in the standalone VM to use 64-bit integers
R=floitsch@google.com
BUG=

Review URL: https://codereview.chromium.org//17878002

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@24466 260f80e4-7a28-3924-810f-c04153c831b5
2013-06-26 13:33:10 +00:00
smok@google.com ebbc2020a2 Put everything in runtime/bin into '::dart::bin' namespace.
Review URL: https://codereview.chromium.org//14341015

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@22032 260f80e4-7a28-3924-810f-c04153c831b5
2013-04-25 14:22:30 +00:00
ager@google.com 26c4b3a58d Fix file descriptor leak in event handler implementation. When shutting down an isolate, we did not destruct the eventhandler so we leaked the file descriptors for it.
Also fix leak of monitor wait data objects on Windows.

R=sgjesse@google.com
BUG=dartbug.com/9021

Review URL: https://codereview.chromium.org//12646007

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@19921 260f80e4-7a28-3924-810f-c04153c831b5
2013-03-13 11:11:38 +00:00
ager@google.com 5c9f9ef74f Avoid needless int64_t to intptr_t conversion in eventhandler.
R=sgjesse@google.com
BUG=

Review URL: https://codereview.chromium.org//10962026

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@12693 260f80e4-7a28-3924-810f-c04153c831b5
2012-09-21 11:40:40 +00:00
asiva@google.com 9d123e5366 Move hashmap.h and hashmap.cc from the 'bin' directory to 'platform' directory so that it can be used from VM code too.
Review URL: https://chromiumcodereview.appspot.com//10853009

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@10261 260f80e4-7a28-3924-810f-c04153c831b5
2012-08-03 22:11:30 +00:00
ager@google.com f791a12b38 Terminate event handler thread on isolate shutdown.
R=sgjesse@google.com
BUG=
TEST=

Review URL: https://chromiumcodereview.appspot.com//10693039

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@9251 260f80e4-7a28-3924-810f-c04153c831b5
2012-06-29 14:40:17 +00:00
ager@google.com e4f7a8d620 Use epoll for the event handler on Linux.
epoll is faster than poll and we avoid iterating all potential
file descriptors all the time.

R=sgjesse@google.com
BUG=
TEST=

Review URL: https://chromiumcodereview.appspot.com//9332003

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@3980 260f80e4-7a28-3924-810f-c04153c831b5
2012-02-07 08:19:33 +00:00
sgjesse@google.com 42b70dcddb Change the thread interface in runtime/platform and use it starting all threads
The platform thread interface (dart::thread) is now refactored to an
all static interface as suggested by iposva@ and asiva@. Use this
interface for running all threads in the VM.

R=ager@google.com, iposva@google.com

BUG=
TEST=

Review URL: https://chromiumcodereview.appspot.com//9141005

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@3830 260f80e4-7a28-3924-810f-c04153c831b5
2012-02-02 08:59:26 +00:00
sgjesse@google.com c1d041500f Use hash map for event handler file descriptor map
Instead of using an array indexed using the file descriptor for
looking up data associated with a socket (SocketData objects) this is
now stored in a hash map using the file descriptor as key.

Added hash map implementation like the one used in the V8 project.

R=ager@google.com, whesse@google.com

BUG=
TEST=

Review URL: https://chromiumcodereview.appspot.com//9186035

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@3483 260f80e4-7a28-3924-810f-c04153c831b5
2012-01-23 09:10:51 +00:00
sgjesse@google.com 3a02bcfc04 Add additional include guard in platform specific .h files
R=ager@google.com

BUG=
TEST=

Review URL: https://chromiumcodereview.appspot.com//9264006

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@3433 260f80e4-7a28-3924-810f-c04153c831b5
2012-01-19 13:37:26 +00:00
sgjesse@google.com a6071e0880 Thread pool changes
Make one global thread pool instead of a thread pool for each
eventhandler (i.e. isolate).

Also:

* Added handler function for thread pool tasks.
* Added thread pool shutdown.
* Added a simple test.

R=ager@google.com

BUG=
TEST=

Review URL: http://codereview.chromium.org//9112013

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@3079 260f80e4-7a28-3924-810f-c04153c831b5
2012-01-09 07:38:30 +00:00
sgjesse@google.com 73c2a13913 Start of thread pool implementation
This the initial commit for adding a thread pool to the Dart
server. For now it is hidden behind a flag (--enable_thread_pool)
and when enabled just starts up and processes 100 void tasks.

Mac OS implementation is not tested and Windows implementation is
still pending.

As we are currently not sharing anything between bin/ and vm/ I
have just used pthread calls directly in the Linux and Mac OS
implementation code. However with Monitor and Thread classes from
vm/ the thread pool could be written platform independently. This
can always be changed later.

R=ager@google.com

BUG=
TEST=

Review URL: http://codereview.chromium.org//8983017

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@2946 260f80e4-7a28-3924-810f-c04153c831b5
2012-01-04 15:16:06 +00:00
sgjesse@google.com 8055ffeb77 Add close to input stream and cleanup socket and streams
* All input streams now have a close method for just cutting
  the stream
* Removed interfaces FileInputStream and FileOutputStream
* Added exceptions to socket to avoid mixing stream and non-stream
  use of the same socket
* Added special handling of the socket connect handler callback

R=ager@google.com

BUG=
TEST=

Review URL: http://codereview.chromium.org//9029001

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@2893 260f80e4-7a28-3924-810f-c04153c831b5
2012-01-02 13:00:59 +00:00
sgjesse@google.com 5950638350 Better handling of stdin/stdout/stderr
When using stdout/stderr it is no longer necessary to explicitly
close the streams for the program to terminate. The automatic
close is handled by always closing the associated receive port
for write only streams when not waiting for any events. If a
close or error handler is installed for stdout/stderr these will
still keep the program alive.

For stdin better handling of the difference between sockets and
pipes have been immplemented. As a special case for stdin when
reading from a terminal the a POLLIN signal with 0 available
bytes is treated as end-of-file. This will trigger when pressing
ctrl-d in a terminal as POLLHUP is not set in that situation.

R=ager@google.com

BUG=
TEST=

Review URL: http://codereview.chromium.org//8533005

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@1507 260f80e4-7a28-3924-810f-c04153c831b5
2011-11-14 14:47:58 +00:00
sgjesse@google.com 516d71ab0b Change the handling of closing sockets
Sockets now supports being half-closed for either reading or writing. When a socket is closed it is by default closed for both read and write and the underlying file descriptor is destroyed. However the socket close can be asked to only half-close the socket to send end of stream to the other end and still have the ability to receive more data.

The close event on a socket is only emitted when the socket is closed by the other end. Both half-close and full-close by the other end is reported as a close event. If a socket is already half closed the close event will automatically destroy the socket.

The streams on the sockets also takes advantage of this. A socket input stream will report a close event when the other end closed. A socket output stream will half-close the socket when close is called making it possible to still receive data on the input stream. When both streams have been closed the socket is destroyed.

For sockets operating on pipes they are initially created as half-closed for either reading or writing depending on which type of pipe a socket object is based on. A pipe for writing will start half-closed for reading so if it is only half-closed for writing the socket will still be destroyed. Same with a pipe for reading that will start half-closed for writing and when a close event is received half-closing the other direction will destroy the socket. Socket objects based on pipes are only exposed through streams.

Extended the socket close test to test a number of different scenarios.

Also refactor the socket data C++ object to encapsulate more socket information and operations.

Now the Linux and Mac OS versions are 100% the same as it turned out that using POLLRDHUP on Linux was not required any more.

R=ager@google.com

BUG=
TEST=

Review URL: http://codereview.chromium.org//8437090

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@1196 260f80e4-7a28-3924-810f-c04153c831b5
2011-11-04 12:34:43 +00:00
sgjesse@google.com 032de2585d Some Linux and Mac OS event handler refactoring
This moved some of the handling of the data on a socket to a socket data object.

This is a step in preparation for another change where more state will be stored on socket data object.

This is also a step in moving from an array of socket data objects indexed by the file descriptor to a hash map of socket data objects.

R=ager@google.com

BUG=
TEST=

Review URL: http://codereview.chromium.org//8431027

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@1001 260f80e4-7a28-3924-810f-c04153c831b5
2011-11-01 11:54:14 +00:00
sgjesse@google.com 6568436be7 Explicitly handle listen sockets and connection sockets differently in Linux and Mac OS eventhandler
Previously the assumption was that an POLLIN event with no data available was from a listen socket with pending accepts. However a POLLIN event from a connection socket can have no data available if the data has been read before the event is processed.

R=ager@google.com

BUG=
TEST=

Review URL: http://codereview.chromium.org//8399039

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@878 260f80e4-7a28-3924-810f-c04153c831b5
2011-10-28 09:30:42 +00:00
dgrove@google.com 4c0f559d23 Initial checkin.
git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@15 260f80e4-7a28-3924-810f-c04153c831b5
2011-10-05 05:20:07 +00:00