| 114 | |
| 115 | |
| 116 | DWORD Ext2PipeControl(PPIPE_REQ *pr, ULONG *len) |
| 117 | { |
| 118 | PPIPE_REQ p; |
| 119 | PREQ_QUERY_DRV q; |
| 120 | PIPE_REQ ac; |
| 121 | DWORD le; |
| 122 | DWORD bytes = 0; |
| 123 | DWORD rc = 0; |
| 124 | int tries = 0; |
| 125 | |
| 126 | p = *pr; |
| 127 | q = (PREQ_QUERY_DRV)p->data; |
| 128 | |
| 129 | Reopen_try: |
| 130 | |
| 131 | /* just try to connect pipe anyway */ |
| 132 | if (NULL == Ext2OpenPipe(EXT2_MGR_SRV)) { |
| 133 | printf("failed to connect to server.\n"); |
| 134 | if (Ext2StartExt2Srv()) { |
| 135 | goto Reopen_try; |
| 136 | } |
| 137 | goto errorout; |
| 138 | } |
| 139 | |
| 140 | // send a message to srv |
| 141 | rc = Ext2WritePipe(g_hPipe, p, p->len, &bytes); |
| 142 | if (!rc || bytes != p->len) { |
| 143 | le = GetLastError(); |
| 144 | if (le == ERROR_NO_DATA && tries++ < 10) { |
| 145 | Ext2ClosePipe(); |
| 146 | Sleep(500 * tries); |
| 147 | goto Reopen_try; |
| 148 | } |
| 149 | goto errorout; |
| 150 | } |
| 151 | |
| 152 | bytes = 0; |
| 153 | memset(&ac, 0, sizeof(ac)); |
| 154 | rc = Ext2ReadPipe(g_hPipe, &ac, sizeof(ac), &bytes); |
| 155 | if (!rc || bytes != sizeof(ac)) { |
| 156 | le = GetLastError(); |
| 157 | goto errorout; |
| 158 | } |
| 159 | if (*len < ac.len) { |
| 160 | if (p) { |
| 161 | delete [] p; |
| 162 | } |
| 163 | *len = ac.len; |
| 164 | p = (PIPE_REQ *) new CHAR[*len]; |
| 165 | *pr = p; |
| 166 | if (!p) { |
| 167 | goto errorout; |
| 168 | } |
| 169 | } |
| 170 | |
| 171 | memset(p, 0, *len); |
| 172 | memcpy(p, &ac, sizeof(ac)); |
| 173 | rc = Ext2ReadPipe(g_hPipe, &p->data[0], |
no test coverage detected