| 76 | } |
| 77 | |
| 78 | int64_t MessageEndpoint::Call(uint64_t id, uint16_t size, uint64_t data, uint64_t rID, uint16_t* rSize, uint64_t* rData, int64_t timeout){ |
| 79 | if(!peer.get()){ |
| 80 | return -ENOTCONN; |
| 81 | } |
| 82 | |
| 83 | if(size > maxMessageSize){ |
| 84 | return -EINVAL; |
| 85 | } |
| 86 | |
| 87 | assert(rSize); |
| 88 | assert(rData); |
| 89 | |
| 90 | Semaphore s = Semaphore(0); |
| 91 | Message m; |
| 92 | |
| 93 | acquireLock(&waitingResponseLock); |
| 94 | waitingResponse.add_back({&s, {&m, rID}}); |
| 95 | releaseLock(&waitingResponseLock); |
| 96 | |
| 97 | Write(id, size, data); // Send message |
| 98 | |
| 99 | // TODO: timeout |
| 100 | s.Wait(); // Await reponse |
| 101 | |
| 102 | *rSize = m.size; |
| 103 | |
| 104 | if(m.size <= 8){ |
| 105 | *rData = m.data; |
| 106 | } else { |
| 107 | memcpy(rData, m.dataP, m.size); |
| 108 | } |
| 109 | |
| 110 | if(m.size > 8){ |
| 111 | delete[] m.dataP; |
| 112 | } |
| 113 | |
| 114 | return 0; |
| 115 | } |
| 116 | |
| 117 | int64_t MessageEndpoint::Write(uint64_t id, uint16_t size, uint64_t data){ |
| 118 | if(!peer.get()){ |