diff options
author | Jakob Odersky <jakob@inpher.io> | 2019-10-09 20:32:48 -0400 |
---|---|---|
committer | Jakob Odersky <jakob@inpher.io> | 2019-10-09 20:33:16 -0400 |
commit | f67c8d59a26132a8d7c80b3e15bddc35ba0091d9 (patch) | |
tree | eb733861e64397d7b36b2ee00aa97e8a92a9044f /client | |
parent | 0ceee5ed4bae240b8c8e94d2fd7424d9d0b67ec7 (diff) | |
download | scala-triad-f67c8d59a26132a8d7c80b3e15bddc35ba0091d9.tar.gz scala-triad-f67c8d59a26132a8d7c80b3e15bddc35ba0091d9.tar.bz2 scala-triad-f67c8d59a26132a8d7c80b3e15bddc35ba0091d9.zip |
format
Diffstat (limited to 'client')
-rw-r--r-- | client/src/Main.scala | 13 | ||||
-rw-r--r-- | client/src/http/CurlBackend.scala | 59 | ||||
-rw-r--r-- | client/src/http/curl.scala | 16 |
3 files changed, 55 insertions, 33 deletions
diff --git a/client/src/Main.scala b/client/src/Main.scala index 4b11fe0..f87be2a 100644 --- a/client/src/Main.scala +++ b/client/src/Main.scala @@ -27,10 +27,12 @@ object Main { val message = Message(content, author).toJson.compactPrint - val req = Request("POST", - s"$server/messages", - Map("Content-type" -> "application/json"), - message.getBytes("utf-8")) + val req = Request( + "POST", + s"$server/messages", + Map("Content-type" -> "application/json"), + message.getBytes("utf-8") + ) if (verbose) { System.err.println(req.url) @@ -43,7 +45,8 @@ object Main { sys.exit(0) case resp => System.err.println( - s"Bad response code while posting message ${resp.statusCode}.") + s"Bad response code while posting message ${resp.statusCode}." + ) sys.exit(1) } } catch { diff --git a/client/src/http/CurlBackend.scala b/client/src/http/CurlBackend.scala index 4dc8577..ff1cf7d 100644 --- a/client/src/http/CurlBackend.scala +++ b/client/src/http/CurlBackend.scala @@ -32,8 +32,10 @@ object CurlBackend { def allocHead() = allocAppend(0, NullPtr[Chunk]) - def allocAppend(size: CSize, - head: Ptr[Chunk] = NullPtr[Chunk]): Ptr[Chunk] = { + def allocAppend( + size: CSize, + head: Ptr[Chunk] = NullPtr[Chunk] + ): Ptr[Chunk] = { val chunk: Ptr[Chunk] = stdlib.malloc(sizeof[Chunk]).cast[Ptr[Chunk]] if (chunk == NullPtr[Chunk]) return NullPtr[Chunk] @@ -73,7 +75,7 @@ object CurlBackend { var chunk = head do { val next = chunk.next - var i = 0l + var i = 0L while (i < next.size) { buffer += next.buffer(i) i += 1 @@ -88,7 +90,7 @@ object CurlBackend { do { val next = chunk.next val buffer = new ArrayBuffer[Byte]() - var i = 0l + var i = 0L while (i < next.size) { buffer += next.buffer(i) i += 1 @@ -100,10 +102,12 @@ object CurlBackend { } - private def receive(data: Ptr[Byte], - size: CSize, - nmemb: CSize, - userdata: Ptr[Byte]): CSize = { + private def receive( + data: Ptr[Byte], + size: CSize, + nmemb: CSize, + userdata: Ptr[Byte] + ): CSize = { val head = userdata.cast[Ptr[Chunk]] val length = size * nmemb val chunk = Chunk.allocAppend(length, head) @@ -135,19 +139,25 @@ object CurlBackend { () => curl_easy_setopt(curl, CURLoption.CURLOPT_ERRORBUFFER, errorBuffer), () => - curl_easy_setopt(curl, - CURLoption.CURLOPT_CUSTOMREQUEST, - toCString(request.method)), + curl_easy_setopt( + curl, + CURLoption.CURLOPT_CUSTOMREQUEST, + toCString(request.method) + ), () => - curl_easy_setopt(curl, - CURLoption.CURLOPT_URL, - toCString(request.url)), + curl_easy_setopt( + curl, + CURLoption.CURLOPT_URL, + toCString(request.url) + ), () => { val buffer = ArrayUtils.toBuffer(request.body) curl_easy_setopt(curl, CURLoption.CURLOPT_POSTFIELDS, buffer) - curl_easy_setopt(curl, - CURLoption.CURLOPT_POSTFIELDSIZE, - request.body.size) + curl_easy_setopt( + curl, + CURLoption.CURLOPT_POSTFIELDSIZE, + request.body.size + ) }, () => { for ((k, v) <- request.headers) { @@ -161,9 +171,11 @@ object CurlBackend { () => curl_easy_setopt(curl, CURLoption.CURLOPT_WRITEDATA, responseChunks), () => - curl_easy_setopt(curl, - CURLoption.CURLOPT_HEADERDATA, - responseHeaderChunks), + curl_easy_setopt( + curl, + CURLoption.CURLOPT_HEADERDATA, + responseHeaderChunks + ), () => curl_easy_perform(curl) ) @@ -186,13 +198,16 @@ object CurlBackend { statusCode = (!responseCode).toInt, headers = responseHeaders.toMap, body = Chunk.toArray(responseChunks) - )) + ) + ) case code => val message = curl_easy_strerror(curl, code) Failure( new RuntimeException( - s"${fromCString(errorBuffer)} (curl exit status $code)")) + s"${fromCString(errorBuffer)} (curl exit status $code)" + ) + ) } Chunk.freeAll(responseChunks) Chunk.freeAll(responseHeaderChunks) diff --git a/client/src/http/curl.scala b/client/src/http/curl.scala index 1eda584..97a867e 100644 --- a/client/src/http/curl.scala +++ b/client/src/http/curl.scala @@ -59,15 +59,19 @@ object curl { def curl_easy_init(): CURL = extern - def curl_easy_setopt(curl: CURL, - option: CURLoption, - parameter: CVararg*): CURLcode = extern + def curl_easy_setopt( + curl: CURL, + option: CURLoption, + parameter: CVararg* + ): CURLcode = extern def curl_easy_perform(curl: CURL): CURLcode = extern - def curl_easy_getinfo(curl: CURL, - option: CURLINFO, - parameter: CVararg*): CURLcode = extern + def curl_easy_getinfo( + curl: CURL, + option: CURLINFO, + parameter: CVararg* + ): CURLcode = extern def curl_easy_cleanup(curl: CURL): Unit = extern |