| OLD | NEW |
| 1 // Copyright (c) 2014, the Fletch project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Fletch project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE.md file. | 3 // BSD-style license that can be found in the LICENSE.md file. |
| 4 | 4 |
| 5 part of system; | 5 part of system; |
| 6 | 6 |
| 7 const int EVFILT_READ = -1; | 7 const int EVFILT_READ = -1; |
| 8 const int EVFILT_WRITE = -2; | 8 const int EVFILT_WRITE = -2; |
| 9 | 9 |
| 10 const int EV_ADD = 0x1; | 10 const int EV_ADD = 0x1; |
| 11 const int EV_DELETE = 0x2; | 11 const int EV_DELETE = 0x2; |
| 12 const int EV_ENABLE = 0x4; | 12 const int EV_ENABLE = 0x4; |
| 13 const int EV_DISABLE = 0x8; | 13 const int EV_DISABLE = 0x8; |
| 14 const int EV_ONESHOT = 0x10; | 14 const int EV_ONESHOT = 0x10; |
| 15 const int EV_CLEAR = 0x20; | 15 const int EV_CLEAR = 0x20; |
| 16 const int EV_EOF = 0x8000; | 16 const int EV_EOF = 0x8000; |
| 17 | 17 |
| 18 class MacOSAddrInfo extends AddrInfo { | 18 class MacOSAddrInfo extends AddrInfo { |
| 19 MacOSAddrInfo() : super._(); | 19 MacOSAddrInfo() : super._(); |
| 20 MacOSAddrInfo.fromAddress(int address) : super._fromAddress(address); | 20 MacOSAddrInfo.fromAddress(int address) : super._fromAddress(address); |
| 21 | 21 |
| 22 get ai_canonname { | 22 get ai_canonname { |
| 23 int offset = _addrlenOffset + wordSize; | 23 int offset = _addrlenOffset + wordSize; |
| 24 return getWord(offset); | 24 return getWord(offset); |
| 25 } | 25 } |
| 26 | 26 |
| 27 Foreign get ai_addr { | 27 ForeignMemory get ai_addr { |
| 28 int offset = _addrlenOffset + wordSize * 2; | 28 int offset = _addrlenOffset + wordSize * 2; |
| 29 return new Foreign.fromAddress(getWord(offset), ai_addrlen); | 29 return new ForeignMemory.fromAddress(getWord(offset), ai_addrlen); |
| 30 } | 30 } |
| 31 | 31 |
| 32 AddrInfo get ai_next { | 32 AddrInfo get ai_next { |
| 33 int offset = _addrlenOffset + wordSize * 3; | 33 int offset = _addrlenOffset + wordSize * 3; |
| 34 return new MacOSAddrInfo.fromAddress(getWord(offset)); | 34 return new MacOSAddrInfo.fromAddress(getWord(offset)); |
| 35 } | 35 } |
| 36 } | 36 } |
| 37 | 37 |
| 38 class KEvent extends Struct { | 38 class KEvent extends Struct { |
| 39 KEvent() : super.finalize(6); | 39 KEvent() : super.finalize(6); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 59 | 59 |
| 60 get fflags => getInt32(wordSize + 4); | 60 get fflags => getInt32(wordSize + 4); |
| 61 get data => getWord(wordSize + 8); | 61 get data => getWord(wordSize + 8); |
| 62 get udata => getWord(wordSize + 8 + wordSize); | 62 get udata => getWord(wordSize + 8 + wordSize); |
| 63 void set udata(int value) { | 63 void set udata(int value) { |
| 64 setWord(wordSize + 8 + wordSize, value); | 64 setWord(wordSize + 8 + wordSize, value); |
| 65 } | 65 } |
| 66 } | 66 } |
| 67 | 67 |
| 68 class MacOSSystem extends PosixSystem { | 68 class MacOSSystem extends PosixSystem { |
| 69 static final Foreign _kevent = Foreign.lookup("kevent"); | 69 static final ForeignFunction _kevent = |
| 70 static final Foreign _lseekMac = Foreign.lookup("lseek"); | 70 ForeignLibrary.standard.lookup("kevent"); |
| 71 static final Foreign _openMac = Foreign.lookup("open"); | 71 static final ForeignFunction _lseekMac = |
| 72 ForeignLibrary.standard.lookup("lseek"); |
| 73 static final ForeignFunction _openMac = |
| 74 ForeignLibrary.standard.lookup("open"); |
| 72 | 75 |
| 73 final KEvent _kEvent = new KEvent(); | 76 final KEvent _kEvent = new KEvent(); |
| 74 | 77 |
| 75 int get FIONREAD => 0x4004667f; | 78 int get FIONREAD => 0x4004667f; |
| 76 | 79 |
| 77 int get SOL_SOCKET => 0xffff; | 80 int get SOL_SOCKET => 0xffff; |
| 78 | 81 |
| 79 int get SO_REUSEADDR => 0x4; | 82 int get SO_REUSEADDR => 0x4; |
| 80 | 83 |
| 81 Foreign get _lseek => _lseekMac; | 84 ForeignFunction get _lseek => _lseekMac; |
| 82 Foreign get _open => _openMac; | 85 ForeignFunction get _open => _openMac; |
| 83 | 86 |
| 84 int _setEvents(bool read, bool write) { | 87 int _setEvents(bool read, bool write) { |
| 85 int eh = System.eventHandler; | 88 int eh = System.eventHandler; |
| 86 int status = 0; | 89 int status = 0; |
| 87 if (read) { | 90 if (read) { |
| 88 _kEvent.filter = EVFILT_READ; | 91 _kEvent.filter = EVFILT_READ; |
| 89 status = _retry(() => _kevent.icall$6(eh, | 92 status = _retry(() => _kevent.icall$6(eh, |
| 90 _kEvent, | 93 _kEvent, |
| 91 1, | 94 1, |
| 92 Foreign.NULL, | 95 Foreign.NULL, |
| (...skipping 21 matching lines...) Expand all Loading... |
| 114 throw "Listening for both READ_EVENT and WRITE_EVENT is currently" | 117 throw "Listening for both READ_EVENT and WRITE_EVENT is currently" |
| 115 " unsupported on mac os."; | 118 " unsupported on mac os."; |
| 116 } | 119 } |
| 117 _kEvent.clear(); | 120 _kEvent.clear(); |
| 118 _kEvent.ident = fd; | 121 _kEvent.ident = fd; |
| 119 _kEvent.flags = EV_ADD | EV_ONESHOT; | 122 _kEvent.flags = EV_ADD | EV_ONESHOT; |
| 120 _kEvent.udata = System._incrementPortRef(port); | 123 _kEvent.udata = System._incrementPortRef(port); |
| 121 return _setEvents((mask & READ_EVENT) != 0, (mask & WRITE_EVENT) != 0); | 124 return _setEvents((mask & READ_EVENT) != 0, (mask & WRITE_EVENT) != 0); |
| 122 } | 125 } |
| 123 } | 126 } |
| OLD | NEW |