 |
Changeset 2900
- Timestamp:
- 11/20/07 17:56:55
(1 year ago)
- Author:
- schveiguy
- Message:
Updated to use new TimeSpan? struct and DateTime? for all date/time related functi
ons. THIS IS A BREAKING CHANGE.
closes #671
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| r2731 |
r2900 |
|
| 6 | 6 | install tango/core/Memory.di $INCLUDE_PREFIX/tango/core ; \ |
|---|
| 7 | 7 | install tango/core/Runtime.di $INCLUDE_PREFIX/tango/core ; \ |
|---|
| 8 | | install tango/core/Thread.di $INCLUDE_PREFIX/tango/core |
|---|
| | 8 | install tango/core/Thread.di $INCLUDE_PREFIX/tango/core ; \ |
|---|
| | 9 | install tango/core/TimeSpan.di $INCLUDE_PREFIX/tango/core |
|---|
| 9 | 10 | version (GNU) { |
|---|
| 10 | 11 | prebuild = $DSSS_BUILD -obj -explicit lib/common/tango/core/BitManip.d -fintfc-file=tango/core/BitManip.di ; \ |
|---|
| … | … | |
| 12 | 13 | $DSSS_BUILD -obj -explicit lib/common/tango/core/Memory.d -fintfc-file=tango/core/Memory.di ; \ |
|---|
| 13 | 14 | $DSSS_BUILD -obj -explicit lib/common/tango/core/Runtime.d -fintfc-file=tango/core/Runtime.di ; \ |
|---|
| 14 | | $DSSS_BUILD -obj -explicit lib/common/tango/core/Thread.d -fintfc-file=tango/core/Thread.di |
|---|
| | 15 | $DSSS_BUILD -obj -explicit lib/common/tango/core/Thread.d -fintfc-file=tango/core/Thread.di ; \ |
|---|
| | 16 | $DSSS_BUILD -obj -explicit lib/common/tango/core/TimeSpan.d -fintfc-file=tango/core/TimeSpan.di |
|---|
| 15 | 17 | } else version (DigitalMars) { |
|---|
| 16 | 18 | prebuild = $DSSS_BUILD -obj -explicit lib/common/tango/core/BitManip.d -Hftango/core/BitManip.di ; \ |
|---|
| … | … | |
| 18 | 20 | $DSSS_BUILD -obj -explicit lib/common/tango/core/Memory.d -Hftango/core/Memory.di ; \ |
|---|
| 19 | 21 | $DSSS_BUILD -obj -explicit lib/common/tango/core/Runtime.d -Hftango/core/Runtime.di ; \ |
|---|
| 20 | | $DSSS_BUILD -obj -explicit lib/common/tango/core/Thread.d -Hftango/core/Thread.di |
|---|
| | 22 | $DSSS_BUILD -obj -explicit lib/common/tango/core/Thread.d -Hftango/core/Thread.di ; \ |
|---|
| | 23 | $DSSS_BUILD -obj -explicit lib/common/tango/core/TimeSpan.d -Hftango/core/TimeSpan.di |
|---|
| 21 | 24 | } |
|---|
| 22 | 25 | |
|---|
| r2525 |
r2900 |
|
| 103 | 103 | uint closeCount = 0; |
|---|
| 104 | 104 | uint errorCount = 0; |
|---|
| 105 | | Time start = Clock.now; |
|---|
| | 105 | DateTime start = Clock.now; |
|---|
| 106 | 106 | Thread clientThread; |
|---|
| 107 | 107 | |
|---|
| … | … | |
| 113 | 113 | try |
|---|
| 114 | 114 | { |
|---|
| 115 | | Interval timeout = 1.0; // 1 sec |
|---|
| | 115 | TimeSpan timeout = TimeSpan.seconds(1); |
|---|
| 116 | 116 | InternetAddress addr = new InternetAddress(SERVER_ADDR, SERVER_PORT); |
|---|
| 117 | 117 | ServerSocket serverSocket = new ServerSocket(addr, 5); |
|---|
| … | … | |
| 294 | 294 | failedConnectCount, failedReceiveCount, failedSendCount, errorCount)); |
|---|
| 295 | 295 | |
|---|
| 296 | | log.info(sprint("Total time: {0} ms", cast(uint) ((Clock.now - start) / start.TicksPerMillisecond))); |
|---|
| | 296 | log.info(sprint("Total time: {0} ms", cast(uint) (Clock.now - start).milliseconds)); |
|---|
| 297 | 297 | |
|---|
| 298 | 298 | clientThread.join(); |
|---|
| r2465 |
r2900 |
|
| 22 | 22 | |
|---|
| 23 | 23 | // get GMT difference in minutes |
|---|
| 24 | | auto tz = cast(int) (WallClock.zone / Time.TicksPerMinute); |
|---|
| | 24 | auto tz = cast(int) WallClock.zone.minutes; |
|---|
| 25 | 25 | char sign = '+'; |
|---|
| 26 | 26 | if (tz < 0) |
|---|
| r2624 |
r2900 |
|
| 15 | 15 | public |
|---|
| 16 | 16 | { |
|---|
| 17 | | import tango.core.Type : Interval; |
|---|
| | 17 | import tango.core.TimeSpan; |
|---|
| 18 | 18 | } |
|---|
| 19 | 19 | private |
|---|
| … | … | |
| 763 | 763 | * ------------------------------------------------------------------------- |
|---|
| 764 | 764 | */ |
|---|
| 765 | | static void sleep( Interval period ) |
|---|
| | 765 | static void sleep( TimeSpan period ) |
|---|
| 766 | 766 | in |
|---|
| 767 | 767 | { |
|---|
| 768 | | assert( period * 1_000 < uint.max - 1 ); |
|---|
| | 768 | assert( period.milliseconds < uint.max - 1 ); |
|---|
| 769 | 769 | } |
|---|
| 770 | 770 | body |
|---|
| … | … | |
| 772 | 772 | version( Win32 ) |
|---|
| 773 | 773 | { |
|---|
| 774 | | Sleep( cast(uint)( period * 1_000 ) ); |
|---|
| | 774 | Sleep( cast(uint)( period.milliseconds ) ); |
|---|
| 775 | 775 | } |
|---|
| 776 | 776 | else version( Posix ) |
|---|
| … | … | |
| 779 | 779 | timespec tout = void; |
|---|
| 780 | 780 | |
|---|
| 781 | | if( tin.tv_sec.max < period ) |
|---|
| | 781 | if( tin.tv_sec.max < period.seconds ) |
|---|
| 782 | 782 | { |
|---|
| 783 | 783 | tin.tv_sec = tin.tv_sec.max; |
|---|
| … | … | |
| 786 | 786 | else |
|---|
| 787 | 787 | { |
|---|
| 788 | | tin.tv_sec = cast(typeof(tin.tv_sec)) period; |
|---|
| 789 | | tin.tv_nsec = cast(typeof(tin.tv_nsec)) ((period % 1.0) * 1_000_000_000); |
|---|
| | 788 | tin.tv_sec = cast(typeof(tin.tv_sec)) period.seconds; |
|---|
| | 789 | tin.tv_nsec = cast(typeof(tin.tv_nsec)) period.nanoseconds % 1_000_000_000; |
|---|
| 790 | 790 | } |
|---|
| 791 | 791 | |
|---|
| … | … | |
| 799 | 799 | } |
|---|
| 800 | 800 | } |
|---|
| | 801 | } |
|---|
| | 802 | |
|---|
| | 803 | /** |
|---|
| | 804 | * Floating point version. The period is in terms of seconds |
|---|
| | 805 | * |
|---|
| | 806 | * Note: The period is not always accurate, so it is possible that the |
|---|
| | 807 | * function would return with a timeout before the specified period. For |
|---|
| | 808 | * more accuracy, use the TimeSpan version. |
|---|
| | 809 | * |
|---|
| | 810 | */ |
|---|
| | 811 | static void sleep( double period ) |
|---|
| | 812 | { |
|---|
| | 813 | sleep(TimeSpan.interval(period)); |
|---|
| 801 | 814 | } |
|---|
| 802 | 815 | |
|---|
| r2863 |
r2900 |
|
| 76 | 76 | core/Runtime.o \ |
|---|
| 77 | 77 | core/Thread.o \ |
|---|
| 78 | | core/ThreadASM.o |
|---|
| | 78 | core/ThreadASM.o \ |
|---|
| | 79 | core/TimeSpan.o |
|---|
| 79 | 80 | |
|---|
| 80 | 81 | OBJ_STDC= \ |
|---|
| … | … | |
| 96 | 97 | core/Memory.html \ |
|---|
| 97 | 98 | core/Runtime.html \ |
|---|
| 98 | | core/Thread.html |
|---|
| | 99 | core/Thread.html \ |
|---|
| | 100 | core/TimeSpan.html |
|---|
| 99 | 101 | |
|---|
| 100 | 102 | ALL_DOCS= |
|---|
| r2809 |
r2900 |
|
| 10 | 10 | |
|---|
| 11 | 11 | |
|---|
| 12 | | public import tango.core.Type; |
|---|
| | 12 | public import tango.core.TimeSpan; |
|---|
| 13 | 13 | public import tango.core.Exception : SyncException; |
|---|
| 14 | 14 | public import tango.core.sync.Mutex; |
|---|
| … | … | |
| 135 | 135 | * Wait up to period seconds for a notification. |
|---|
| 136 | 136 | * |
|---|
| | 137 | * Note: The period is not always accurate, so it is possible that the |
|---|
| | 138 | * function would return with a timeout before the specified period. For |
|---|
| | 139 | * more accuracy, use the TimeSpan version. |
|---|
| | 140 | * |
|---|
| 137 | 141 | * Params: |
|---|
| 138 | 142 | * period = The number of seconds to wait. |
|---|
| … | … | |
| 144 | 148 | * SyncException on error. |
|---|
| 145 | 149 | */ |
|---|
| 146 | | bool wait( Interval period ) |
|---|
| | 150 | bool wait( double period ) |
|---|
| | 151 | { |
|---|
| | 152 | return wait(TimeSpan.interval(period)); |
|---|
| | 153 | } |
|---|
| | 154 | |
|---|
| | 155 | /** |
|---|
| | 156 | * Wait up to the specified time period for a notification. |
|---|
| | 157 | * |
|---|
| | 158 | * Params: |
|---|
| | 159 | * period = The time to wait. |
|---|
| | 160 | * |
|---|
| | 161 | * Returns: |
|---|
| | 162 | * true if notified before the timeout and false if not. |
|---|
| | 163 | * |
|---|
| | 164 | * Throws: |
|---|
| | 165 | * SyncException on error. |
|---|
| | 166 | */ |
|---|
| | 167 | bool wait( TimeSpan period ) |
|---|
| 147 | 168 | { |
|---|
| 148 | 169 | version( Win32 ) |
|---|
| 149 | 170 | { |
|---|
| 150 | | return timedWait( period < INFINITE ? |
|---|
| 151 | | cast(uint)( period * 1_000 ) : INFINITE - 1 ); |
|---|
| | 171 | return timedWait( period.milliseconds < INFINITE ? |
|---|
| | 172 | cast(uint)( period.milliseconds ) : INFINITE - 1 ); |
|---|
| 152 | 173 | } |
|---|
| 153 | 174 | else version( Posix ) |
|---|
| … | … | |
| 519 | 540 | { |
|---|
| 520 | 541 | waiting = true; |
|---|
| 521 | | alertedOne = condReady.wait( 1.0 ); |
|---|
| 522 | | alertedTwo = condReady.wait( 1.0 ); |
|---|
| | 542 | alertedOne = condReady.wait( 1 ); |
|---|
| | 543 | alertedTwo = condReady.wait( 1 ); |
|---|
| 523 | 544 | } |
|---|
| 524 | 545 | } |
|---|
| r2809 |
r2900 |
|
| 10 | 10 | |
|---|
| 11 | 11 | |
|---|
| 12 | | public import tango.core.Type; |
|---|
| | 12 | public import tango.core.TimeSpan; |
|---|
| 13 | 13 | public import tango.core.Exception : SyncException; |
|---|
| 14 | 14 | |
|---|
| … | … | |
| 38 | 38 | |
|---|
| 39 | 39 | |
|---|
| 40 | | void adjTimespec( inout timespec t, Interval i ) |
|---|
| | 40 | void adjTimespec( inout timespec t, TimeSpan i ) |
|---|
| 41 | 41 | { |
|---|
| 42 | 42 | enum |
|---|
| … | … | |
| 45 | 45 | } |
|---|
| 46 | 46 | |
|---|
| 47 | | if( t.tv_sec.max - t.tv_sec < i ) |
|---|
| | 47 | if( t.tv_sec.max - t.tv_sec < i.seconds ) |
|---|
| 48 | 48 | { |
|---|
| 49 | 49 | t.tv_sec = t.tv_sec.max; |
|---|
| … | … | |
| 52 | 52 | else |
|---|
| 53 | 53 | { |
|---|
| 54 | | t.tv_sec += i; |
|---|
| 55 | | i = (i % 1.0) * SECS_TO_NANOS; |
|---|
| 56 | | if( SECS_TO_NANOS - t.tv_nsec < i ) |
|---|
| | 54 | t.tv_sec += i.seconds; |
|---|
| | 55 | long ns = i.nanoseconds % SECS_TO_NANOS; |
|---|
| | 56 | if( SECS_TO_NANOS - t.tv_nsec < ns ) |
|---|
| 57 | 57 | { |
|---|
| 58 | 58 | t.tv_sec += 1; |
|---|
| 59 | | i -= SECS_TO_NANOS; |
|---|
| | 59 | ns -= SECS_TO_NANOS; |
|---|
| 60 | 60 | } |
|---|
| 61 | | t.tv_nsec += cast(typeof(t.tv_sec)) i; |
|---|
| | 61 | t.tv_nsec += cast(typeof(t.tv_sec)) ns; |
|---|
| 62 | 62 | } |
|---|
| 63 | 63 | } |
|---|
| r2809 |
r2900 |
|
| 9 | 9 | |
|---|
| 10 | 10 | |
|---|
| 11 | | public import tango.core.Type; |
|---|
| | 11 | public import tango.core.TimeSpan; |
|---|
| 12 | 12 | public import tango.core.Exception : SyncException; |
|---|
| 13 | 13 | |
|---|
| … | … | |
| 126 | 126 | * Otherwise, return false. |
|---|
| 127 | 127 | * |
|---|
| | 128 | * Note: The period is not always accurate, so it is possible that the |
|---|
| | 129 | * function would return with a timeout before the specified period. For |
|---|
| | 130 | * more accuracy, use the TimeSpan version. |
|---|
| | 131 | * |
|---|
| 128 | 132 | * Params: |
|---|
| 129 | 133 | * period = The number of seconds to wait. |
|---|
| … | … | |
| 135 | 139 | * SyncException on error. |
|---|
| 136 | 140 | */ |
|---|
| 137 | | bool wait( Interval period ) |
|---|
| 138 | | { |
|---|
| 139 | | version( Win32 ) |
|---|
| 140 | | { |
|---|
| 141 | | DWORD t = period < INFINITE ? |
|---|
| 142 | | cast(uint)( period * 1_000 ) : INFINITE - 1; |
|---|
| | 141 | bool wait( double period ) |
|---|
| | 142 | { |
|---|
| | 143 | return wait(TimeSpan.interval(period)); |
|---|
| | 144 | } |
|---|
| | 145 | |
|---|
| | 146 | /** |
|---|
| | 147 | * Wait up to the specified time for the current count to be above zero. |
|---|
| | 148 | * If this occurs, then atomically decrement the count by one and return |
|---|
| | 149 | * true. Otherwise, return false. |
|---|
| | 150 | * |
|---|
| | 151 | * Params: |
|---|
| | 152 | * period = The amount of time to wait. |
|---|
| | 153 | * |
|---|
| | 154 | * Returns: |
|---|
| | 155 | * true if notified before the timeout and false if not. |
|---|
| | 156 | * |
|---|
| | 157 | * Throws: |
|---|
| | 158 | * SyncException on error. |
|---|
| | 159 | */ |
|---|
| | 160 | bool wait( TimeSpan period ) |
|---|
| | 161 | { |
|---|
| | 162 | version( Win32 ) |
|---|
| | 163 | { |
|---|
| | 164 | DWORD t = period.milliseconds < INFINITE ? |
|---|
| | 165 | cast(uint)( period.milliseconds ) : INFINITE - 1; |
|---|
| 143 | 166 | switch( WaitForSingleObject( m_hndl, t ) ) |
|---|
| 144 | 167 | { |
|---|
| r2899 |
r2900 |
|
| 23 | 23 | private import tango.core.Exception; |
|---|
| 24 | 24 | |
|---|
| 25 | | private import tango.core.Type : Time; |
|---|
| | 25 | private import tango.util.time.DateTime; |
|---|
| 26 | 26 | |
|---|
| 27 | 27 | /******************************************************************************* |
|---|
| … | … | |
| 813 | 813 | ***********************************************************************/ |
|---|
| 814 | 814 | |
|---|
| 815 | | final Time modified () |
|---|
| | 815 | final DateTime modified () |
|---|
| 816 | 816 | { |
|---|
| 817 | 817 | return timeStamps.modified; |
|---|
| … | … | |
| 825 | 825 | ***********************************************************************/ |
|---|
| 826 | 826 | |
|---|
| 827 | | final Time accessed () |
|---|
| | 827 | final DateTime accessed () |
|---|
| 828 | 828 | { |
|---|
| 829 | 829 | return timeStamps.accessed; |
|---|
| … | … | |
| 837 | 837 | ***********************************************************************/ |
|---|
| 838 | 838 | |
|---|
| 839 | | final Time created () |
|---|
| | 839 | final DateTime created () |
|---|
| 840 | 840 | { |
|---|
| 841 | 841 | return timeStamps.created; |
|---|
| … | … | |
| 1100 | 1100 | final Stamps timeStamps () |
|---|
| 1101 | 1101 | { |
|---|
| 1102 | | static Time convert (FILETIME time) |
|---|
| | 1102 | static DateTime convert (FILETIME time) |
|---|
| 1103 | 1103 | { |
|---|
| 1104 | | return cast(Time) (Time.TicksTo1601 + *cast(ulong*) &time); |
|---|
| | 1104 | return DateTime.epoch1601 + TimeSpan(*cast(ulong*) &time); |
|---|
| 1105 | 1105 | } |
|---|
| 1106 | 1106 | |
|---|
| … | … | |
| 1418 | 1418 | final Stamps timeStamps () |
|---|
| 1419 | 1419 | { |
|---|
| 1420 | | static Time convert (timeval* tv) |
|---|
| | 1420 | static DateTime convert (timeval* tv) |
|---|
| 1421 | 1421 | { |
|---|
| 1422 | | return cast(Time) (Time.TicksTo1970 + (1_000_000L * |
|---|
| 1423 | | tv.tv_sec + tv.tv_usec) * 10); |
|---|
| | 1422 | return DateTime.epoch1970 + |
|---|
| | 1423 | TimeSpan.seconds(tv.tv_sec) + |
|---|
| | 1424 | TimeSpan.microseconds(tv.tv_usec); |
|---|
| 1424 | 1425 | } |
|---|
| 1425 | 1426 | |
|---|
| … | … | |
| 1649 | 1650 | struct Stamps |
|---|
| 1650 | 1651 | { |
|---|
| 1651 | | Time created, /// time created |
|---|
| 1652 | | accessed, /// last time accessed |
|---|
| 1653 | | modified; /// last time modified |
|---|
| | 1652 | DateTime created, /// time created |
|---|
| | 1653 | accessed, /// last time accessed |
|---|
| | 1654 | modified; /// last time modified |
|---|
| 1654 | 1655 | } |
|---|
| 1655 | 1656 | |
|---|
| … | … | |
| 1776 | 1777 | ***********************************************************************/ |
|---|
| 1777 | 1778 | |
|---|
| 1778 | | abstract Time modified (); |
|---|
| | 1779 | abstract DateTime modified (); |
|---|
| 1779 | 1780 | |
|---|
| 1780 | 1781 | /*********************************************************************** |
|---|
| … | … | |
| 1785 | 1786 | ***********************************************************************/ |
|---|
| 1786 | 1787 | |
|---|
| 1787 | | abstract Time accessed (); |
|---|
| | 1788 | abstract DateTime accessed (); |
|---|
| 1788 | 1789 | |
|---|
| 1789 | 1790 | /*********************************************************************** |
|---|
| … | … | |
| 1794 | 1795 | ***********************************************************************/ |
|---|
| 1795 | 1796 | |
|---|
| 1796 | | abstract Time created (); |
|---|
| | 1797 | abstract DateTime created (); |
|---|
| 1797 | 1798 | |
|---|
| 1798 | 1799 | /*********************************************************************** |
|---|
| r2809 |
r2900 |
|
| 246 | 246 | public int select() |
|---|
| 247 | 247 | { |
|---|
| 248 | | return select(Interval.max); |
|---|
| | 248 | return select(TimeSpan.max); |
|---|
| | 249 | } |
|---|
| | 250 | |
|---|
| | 251 | deprecated public int select(double timeout) |
|---|
| | 252 | { |
|---|
| | 253 | return select(timeout is timeout.max ? TimeSpan.max : TimeSpan.interval(timeout)); |
|---|
| 249 | 254 | } |
|---|
| 250 | 255 | |
|---|
| … | … | |
| 265 | 270 | * wakeup() method has been called from another thread. |
|---|
| 266 | 271 | */ |
|---|
| 267 | | public abstract int select(Interval timeout); |
|---|
| | 272 | public abstract int select(TimeSpan timeout); |
|---|
| 268 | 273 | |
|---|
| 269 | 274 | /** |
|---|
| … | … | |
| 304 | 309 | * Cast the time duration to a C timeval struct. |
|---|
| 305 | 310 | */ |
|---|
| 306 | | public timeval* toTimeval(timeval* tv, Interval interval) |
|---|
| | 311 | public timeval* toTimeval(timeval* tv, TimeSpan interval) |
|---|
| 307 | 312 | in |
|---|
| 308 | 313 | { |
|---|
| … | … | |
| 311 | 316 | body |
|---|
| 312 | 317 | { |
|---|
| 313 | | tv.tv_sec = cast(typeof(tv.tv_sec)) (interval); |
|---|
| 314 | | tv.tv_usec = cast(typeof(tv.tv_usec)) ((interval - tv.tv_sec) * 1_000_000); |
|---|
| | 318 | tv.tv_sec = cast(typeof(tv.tv_sec)) interval.seconds; |
|---|
| | 319 | tv.tv_usec = cast(typeof(tv.tv_usec)) (interval.microseconds % 1_000_000); |
|---|
| 315 | 320 | return tv; |
|---|
| 316 | 321 | } |
|---|
| r2809 |
r2900 |
|
| 339 | 339 | * |
|---|
| 340 | 340 | * Params: |
|---|
| 341 | | * timeout = Interval with the maximum amount of time that the |
|---|
| | 341 | * timeout = TimeSpan with the maximum amount of time that the |
|---|
| 342 | 342 | * selector will wait for events from the conduits; the |
|---|
| 343 | 343 | * amount of time is relative to the current system time |
|---|
| … | … | |
| 356 | 356 | * resources available to wait for events from the conduits. |
|---|
| 357 | 357 | */ |
|---|
| 358 | | public int select(Interval timeout) |
|---|
| 359 | | { |
|---|
| 360 | | int to = cast(int) (timeout != Interval.max ? cast(int) (timeout * 1000) : -1); |
|---|
| | 358 | public int select(TimeSpan timeout) |
|---|
| | 359 | { |
|---|
| | 360 | int to = (timeout != TimeSpan.max ? cast(int) timeout.milliseconds : -1); |
|---|
| 361 | 361 | |
|---|
| 362 | 362 | while (true) |
|---|
| r2809 |
r2900 |
|
| 292 | 292 | * |
|---|
| 293 | 293 | * Params: |
|---|
| 294 | | * timeout = Interval with the maximum amount of time that the |
|---|
| | 294 | * timeout = Timespan with the maximum amount of time that the |
|---|
| 295 | 295 | * selector will wait for events from the conduits; the |
|---|
| 296 | 296 | * amount of time is relative to the current system time |
|---|
| … | … | |
| 309 | 309 | * resources available to wait for events from the conduits. |
|---|
| 310 | 310 | */ |
|---|
| 311 | | public int select(Interval timeout) |
|---|
| 312 | | { |
|---|
| 313 | | int to = cast(int) (timeout != Interval.max ? cast(int) (timeout * 1000) : -1); |
|---|
| | 311 | public int select(TimeSpan timeout) |
|---|
| | 312 | { |
|---|
| | 313 | int to = (timeout != TimeSpan.max ? cast(int) timeout.milliseconds : -1); |
|---|
| 314 | 314 | |
|---|
| 315 | 315 | debug (selector) |
|---|
| r2873 |
r2900 |
|
| 411 | 411 | * |
|---|
| 412 | 412 | * Params: |
|---|
| 413 | | * timeout = Interval with the maximum amount of time that the |
|---|
| | 413 | * timeout = TimeSpan with the maximum amount of time that the |
|---|
| 414 | 414 | * selector will wait for events from the conduits; the |
|---|
| 415 | 415 | * amount of time is relative to the current system time |
|---|
| … | … | |
| 428 | 428 | * resources available to wait for events from the conduits. |
|---|
| 429 | 429 | */ |
|---|
| 430 | | public int select(Interval timeout) |
|---|
| | 430 | public int select(TimeSpan timeout) |
|---|
| 431 | 431 | { |
|---|
| 432 | 432 | fd_set *readfds; |
|---|
| … | … | |
| 435 | 435 | timeval tv; |
|---|
| 436 | 436 | |
|---|
| 437 | | int to = cast(int) (timeout != Interval.max ? cast(int) (timeout * 1000) : -1); |
|---|
| 438 | 437 | |
|---|
| 439 | 438 | debug (selector) |
|---|
| 440 | | Stdout.format("--- SelectSelector.select(timeout={0} msec)\n", to); |
|---|
| | 439 | Stdout.format("--- SelectSelector.select(timeout={0} msec)\n", timeout.milliseconds); |
|---|
| 441 | 440 | |
|---|
| 442 | 441 | if (_readSet !is null) |
|---|
| … | … | |
| 472 | 471 | |
|---|
| 473 | 472 | // FIXME: add support for the wakeup() call. |
|---|
| 474 | | _eventCount = .select(_maxfd + 1, readfds, writefds, exceptfds, to is -1 ? null : &tv); |
|---|
| | 473 | _eventCount = .select(_maxfd + 1, readfds, writefds, exceptfds, timeout is TimeSpan.max ? null : &tv); |
|---|
| 475 | 474 | |
|---|
| 476 | 475 | debug (selector) |
|---|
| … | … | |
| 498 | 497 | |
|---|
| 499 | 498 | // FIXME: Can a system call be interrupted on Windows? |
|---|
| 500 | | _eventCount = .select(ISelectable.Handle.max, readfds, writefds, exceptfds, to is -1 ? null : &tv); |
|---|
| | 499 | _eventCount = .select(ISelectable.Handle.max, readfds, writefds, exceptfds, timeout is TimeSpan.max ? null : &tv); |
|---|
| 501 | 500 | |
|---|
| 502 | 501 | debug (selector) |
|---|
| r2809 |
r2900 |
|
| 9 | 9 | public import tango.io.model.IConduit; |
|---|
| 10 | 10 | |
|---|
| 11 | | public import tango.core.Type : Interval; |
|---|
| | 11 | public import tango.core.TimeSpan; |
|---|
| 12 | 12 | |
|---|
| 13 | 13 | /** |
|---|
| … | … | |
| 400 | 400 | * |
|---|
| 401 | 401 | * Params: |
|---|
| 402 | | * timeout = Interval with the maximum amount of time that the |
|---|
| | 402 | * timeout = TimeSpan with the maximum amount of time that the |
|---|
| 403 | 403 | * selector will wait for events from the conduits; the |
|---|
| 404 | 404 | * amount of time is relative to the current system time |
|---|
| … | … | |
| 410 | 410 | * have received events within the specified timeout. |
|---|
| 411 | 411 | */ |
|---|
| 412 | | public abstract int select(Interval timeout); |
|---|
| | 412 | public abstract int select(TimeSpan timeout); |
|---|
| | 413 | |
|---|
| | 414 | /* |
|---|
| | 415 | * Deprecated: use select(TimeSpan) instead |
|---|
| | 416 | * |
|---|
| | 417 | * Params: |
|---|
| | 418 | * timeout = the maximum amount of time in seconds that the |
|---|
| | 419 | * selector will wait for events from the conduits; the |
|---|
| | 420 | * amount of time is relative to the current system time |
|---|
| | 421 | * (i.e. just the number of milliseconds that the selector |
|---|
| | 422 | * has to wait for the events). |
|---|
| | 423 | * |
|---|
| | 424 | * Returns: |
|---|
| | 425 | * The amount of conduits that have received events; 0 if no conduits |
|---|
| | 426 | * have received events within the specified timeout. |
|---|
| | 427 | */ |
|---|
| | 428 | deprecated public abstract int select(double timeout); |
|---|
| 413 | 429 | |
|---|
| 414 | 430 | /** |
|---|
| r2588 |
r2900 |
|
| 67 | 67 | private import tango.core.Exception; |
|---|
| 68 | 68 | |
|---|
| 69 | | private import tango.core.Type : Interval; |
|---|
| | 69 | private import tango.core.TimeSpan; |
|---|
| 70 | 70 | |
|---|
| 71 | 71 | |
|---|
| … | … | |
| 1359 | 1359 | ***********************************************************************/ |
|---|
| 1360 | 1360 | |
|---|
| 1361 | | static int select (SocketSet checkRead, SocketSet checkWrite, SocketSet checkError, Interval time) |
|---|
| | 1361 | static int select (SocketSet checkRead, SocketSet checkWrite, SocketSet checkError, TimeSpan time) |
|---|
| 1362 | 1362 | { |
|---|
| 1363 | 1363 | auto tv = toTimeval (time); |
|---|
| … | … | |
| 1365 | 1365 | } |
|---|
| 1366 | 1366 | |
|---|
| | 1367 | /*********************************************************************** |
|---|
| | 1368 | select with specified timeout |
|---|
| | 1369 | |
|---|
| | 1370 | Note: The period is not always accurate, so it is possible |
|---|
| | 1371 | that the function will return with a timeout before the |
|---|
| | 1372 | specified period. For more accuracy, use the TimeSpan |
|---|
| | 1373 | version. |
|---|
| | 1374 | ***********************************************************************/ |
|---|
| | 1375 | |
|---|
| | 1376 | static int select (SocketSet checkRead, SocketSet checkWrite, SocketSet checkError, double time) |
|---|
| | 1377 | { |
|---|
| | 1378 | return select(checkRead, checkWrite, checkError, TimeSpan.interval(time)); |
|---|
| | 1379 | } |
|---|
| | 1380 | |
|---|
| 1367 | 1381 | |
|---|
| 1368 | 1382 | /*********************************************************************** |
|---|
| … | … | |
| 1379 | 1393 | /*********************************************************************** |
|---|
| 1380 | 1394 | |
|---|
| 1381 | | Handy utility for converting Time into timeval |
|---|
| 1382 | | |
|---|
| 1383 | | ***********************************************************************/ |
|---|
| 1384 | | |
|---|
| 1385 | | static timeval toTimeval (Interval time) |
|---|
| | 1395 | Handy utility for converting TimeSpan into timeval |
|---|
| | 1396 | |
|---|
| | 1397 | ***********************************************************************/ |
|---|
| | 1398 | |
|---|
| | 1399 | static timeval toTimeval (TimeSpan time) |
|---|
| 1386 | 1400 | { |
|---|
| 1387 | 1401 | timeval tv; |
|---|
| 1388 | | tv.tv_sec = cast(uint) time; |
|---|
| 1389 | | tv.tv_usec = cast(uint) ((time - tv.tv_sec) * 1_000_000.0); |
|---|
| | 1402 | tv.tv_sec = cast(uint) time.seconds; |
|---|
| | 1403 | tv.tv_usec = cast(uint) time.microseconds % 1_000_000; |
|---|
| 1390 | 1404 | return tv; |
|---|
| 1391 | 1405 | } |
|---|
| r2739 |
r2900 |
|
| 19 | 19 | private import tango.net.Socket; |
|---|
| 20 | 20 | |
|---|
| 21 | | private import tango.core.Type : Interval; |
|---|
| | 21 | private import tango.core.TimeSpan; |
|---|
| 22 | 22 | |
|---|
| 23 | 23 | /******************************************************************************* |
|---|
| … | … | |
| 121 | 121 | ***********************************************************************/ |
|---|
| 122 | 122 | |
|---|
| 123 | | SocketConduit setTimeout (Interval interval) |
|---|
| | 123 | SocketConduit setTimeout (TimeSpan interval) |
|---|
| 124 | 124 | { |
|---|
| 125 | 125 | tv = socket_.toTimeval (interval); |
|---|
| 126 | 126 | return this; |
|---|
| | 127 | } |
|---|
| | 128 | |
|---|
| | 129 | deprecated SocketConduit setTimeout (double interval) |
|---|
| | 130 | { |
|---|
| | 131 | return setTimeout(TimeSpan.interval(interval)); |
|---|
| 127 | 132 | } |
|---|
| 128 | 133 | |
|---|
| r2809 |
r2900 |
|
| 64 | 64 | ***********************************************************************/ |
|---|
| 65 | 65 | |
|---|
| 66 | | void invalidate (char[] key, Time timeLimit = Time.max) |
|---|
| | 66 | void invalidate (char[] key, DateTime timeLimit = DateTime.max) |
|---|
| 67 | 67 | { |
|---|
| 68 | 68 | assert (key.length); |
|---|
| r2878 |
r2900 |
|
| 93 | 93 | ***********************************************************************/ |
|---|
| 94 | 94 | |
|---|
| 95 | | Time time () |
|---|
| | 95 | DateTime time () |
|---|
| 96 | 96 | { |
|---|
| 97 | 97 | return Clock.now; |
|---|
| r2878 |
r2900 |
|
| 43 | 43 | class NetworkMessage : IMessage |
|---|
| 44 | 44 | { |
|---|
| 45 | | private uint id_; |
|---|
| 46 | | private long time_; |
|---|
| 47 | | private char[] reply_; |
|---|
| | 45 | private uint id_; |
|---|
| | 46 | private DateTime time_; |
|---|
| | 47 | private char[] reply_; |
|---|
| 48 | 48 | |
|---|
| 49 | 49 | /*********************************************************************** |
|---|
| … | … | |
| 98 | 98 | ***********************************************************************/ |
|---|
| 99 | 99 | |
|---|
| 100 | | void time (Time time) |
|---|
| | 100 | void time (DateTime time) |
|---|
| 101 | 101 | { |
|---|
| 102 | 102 | time_ = time; |
|---|
| … | … | |
| 109 | 109 | ***********************************************************************/ |
|---|
| 110 | 110 | |
|---|
| 111 | | Time time () |
|---|
| | 111 | DateTime time () |
|---|
| 112 | 112 | { |
|---|
| 113 | | return cast(Time) time_; |
|---|
| | 113 | return time_; |
|---|
| 114 | 114 | } |
|---|
| 115 | 115 | |
|---|
| … | … | |
| 140 | 140 | void read (IReader input) |
|---|
| 141 | 141 | { |
|---|
| 142 | | input (id_) (time_) (reply_); |
|---|
| | 142 | input (id_) (time_.ticks) (reply_); |
|---|
| 143 | 143 | } |
|---|
| 144 | 144 | |
|---|
| … | … | |
| 151 | 151 | void write (IWriter output) |
|---|
| 152 | 152 | { |
|---|
| 153 | | output (id_) (time_) (reply_); |
|---|
| | 153 | output (id_) (time_.ticks) (reply_); |
|---|
| 154 | 154 | } |
|---|
| 155 | 155 | |
|---|
| r2809 |
r2900 |
|
| 13 | 13 | module tango.net.cluster.QueuedCache; |
|---|
| 14 | 14 | |
|---|
| 15 | | private import tango.core.Type : Time; |
|---|
| | 15 | private import tango.util.time.DateTime; |
|---|
| 16 | 16 | |
|---|
| 17 | 17 | private import tango.net.cluster.model.ICache; |
|---|
| … | … | |
| 116 | 116 | **********************************************************************/ |
|---|
| 117 | 117 | |
|---|
| 118 | | synchronized bool put (K key, V value, Time time = Time.init) |
|---|
| | 118 | synchronized bool put (K key, V value, DateTime time = DateTime.init) |
|---|
| 119 | 119 | { |
|---|
| 120 | 120 | assert (key !is key.init); |
|---|
| … | … | |
| 138 | 138 | **********************************************************************/ |
|---|
| 139 | 139 | |
|---|
| 140 | | synchronized bool put (K peek, K delegate() key, V delegate() value, Time time = Time.init) |
|---|
| | 140 | synchronized bool put (K peek, K delegate() key, V delegate() value, DateTime time = DateTime.init) |
|---|
| 141 | 141 | { |
|---|
| 142 | 142 | assert (peek !is peek.init); |
|---|
| … | … | |
| 162 | 162 | **********************************************************************/ |
|---|
| 163 | 163 | |
|---|
| 164 | | synchronized V remove (K key, Time time = Time.max) |
|---|
| | 164 | synchronized V remove (K key, DateTime time = DateTime.max) |
|---|
| 165 | 165 | { |
|---|
| 166 | 166 | auto e = lookup (key); |
|---|
| … | … | |
| 171 | 171 | // don't actually kill the list entry -- just place |
|---|
| 172 | 172 | // it at the list 'tail' ready for subsequent reuse |
|---|
| 173 | | deReference(e).set (K.init, V.init, Time.min); |
|---|
| | 173 | deReference(e).set (K.init, V.init, DateTime.min); |
|---|
| 174 | 174 | |
|---|
| 175 | 175 | map.remove (key); |
|---|
| … | … | |
| 288 | 288 | QueuedEntry* prev, |
|---|
| 289 | 289 | next; |
|---|
| 290 | | Time time; |
|---|
| | 290 | DateTime time; |
|---|
| 291 | 291 | V value; |
|---|
| 292 | 292 | |
|---|
| … | … | |
| 297 | 297 | **************************************************************/ |
|---|
| 298 | 298 | |
|---|
| 299 | | QueuedEntry* set (K key, V value, Time time) |
|---|
| | 299 | QueuedEntry* set (K key, V value, DateTime time) |
|---|
| 300 | 300 | { |
|---|
| 301 | 301 | &n |
|---|
|