| 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 = ForeignLibrary.main.lookup("kevent"); |
| 70 static final Foreign _lseekMac = Foreign.lookup("lseek"); | 70 static final ForeignFunction _lseekMac = ForeignLibrary.main.lookup("lseek"); |
| 71 static final Foreign _openMac = Foreign.lookup("open"); | 71 static final ForeignFunction _openMac = ForeignLibrary.main.lookup("open"); |
| 72 | 72 |
| 73 final KEvent _kEvent = new KEvent(); | 73 final KEvent _kEvent = new KEvent(); |
| 74 | 74 |
| 75 int get FIONREAD => 0x4004667f; | 75 int get FIONREAD => 0x4004667f; |
| 76 | 76 |
| 77 int get SOL_SOCKET => 0xffff; | 77 int get SOL_SOCKET => 0xffff; |
| 78 | 78 |
| 79 int get SO_REUSEADDR => 0x4; | 79 int get SO_REUSEADDR => 0x4; |
| 80 | 80 |
| 81 Foreign get _lseek => _lseekMac; | 81 ForeignFunction get _lseek => _lseekMac; |
| 82 Foreign get _open => _openMac; | 82 ForeignFunction get _open => _openMac; |
| 83 | 83 |
| 84 int _setEvents(bool read, bool write) { | 84 int _setEvents(bool read, bool write) { |
| 85 int eh = System.eventHandler; | 85 int eh = System.eventHandler; |
| 86 int status = 0; | 86 int status = 0; |
| 87 if (read) { | 87 if (read) { |
| 88 _kEvent.filter = EVFILT_READ; | 88 _kEvent.filter = EVFILT_READ; |
| 89 status = _retry(() => _kevent.icall$6(eh, | 89 status = _retry(() => _kevent.icall$6(eh, |
| 90 _kEvent, | 90 _kEvent, |
| 91 1, | 91 1, |
| 92 Foreign.NULL, | 92 ForeignPointer.NULL, |
| 93 0, | 93 0, |
| 94 Foreign.NULL)); | 94 ForeignPointer.NULL)); |
| 95 } | 95 } |
| 96 if (status != -1 && write) { | 96 if (status != -1 && write) { |
| 97 _kEvent.filter = EVFILT_WRITE; | 97 _kEvent.filter = EVFILT_WRITE; |
| 98 status = _retry(() => _kevent.icall$6(eh, | 98 status = _retry(() => _kevent.icall$6(eh, |
| 99 _kEvent, | 99 _kEvent, |
| 100 1, | 100 1, |
| 101 Foreign.NULL, | 101 ForeignPointer.NULL, |
| 102 0, | 102 0, |
| 103 Foreign.NULL)); | 103 ForeignPointer.NULL)); |
| 104 } | 104 } |
| 105 return status; | 105 return status; |
| 106 } | 106 } |
| 107 | 107 |
| 108 int addToEventHandler(int fd) { } | 108 int addToEventHandler(int fd) { } |
| 109 | 109 |
| 110 int removeFromEventHandler(int fd) { } | 110 int removeFromEventHandler(int fd) { } |
| 111 | 111 |
| 112 int setPortForNextEvent(int fd, Port port, int mask) { | 112 int setPortForNextEvent(int fd, Port port, int mask) { |
| 113 if (mask != READ_EVENT && mask != WRITE_EVENT) { | 113 if (mask != READ_EVENT && mask != WRITE_EVENT) { |
| 114 throw "Listening for both READ_EVENT and WRITE_EVENT is currently" | 114 throw "Listening for both READ_EVENT and WRITE_EVENT is currently" |
| 115 " unsupported on mac os."; | 115 " unsupported on mac os."; |
| 116 } | 116 } |
| 117 _kEvent.clear(); | 117 _kEvent.clear(); |
| 118 _kEvent.ident = fd; | 118 _kEvent.ident = fd; |
| 119 _kEvent.flags = EV_ADD | EV_ONESHOT; | 119 _kEvent.flags = EV_ADD | EV_ONESHOT; |
| 120 _kEvent.udata = System._incrementPortRef(port); | 120 _kEvent.udata = System._incrementPortRef(port); |
| 121 return _setEvents((mask & READ_EVENT) != 0, (mask & WRITE_EVENT) != 0); | 121 return _setEvents((mask & READ_EVENT) != 0, (mask & WRITE_EVENT) != 0); |
| 122 } | 122 } |
| 123 } | 123 } |
| OLD | NEW |